def _webcamCheck(self):
		self.cam = webcam.webcam()
		if self.cam.hasCamera():
			self.camPage = wx.Panel(self.tabs)
			sizer = wx.GridBagSizer(2, 2)
			self.camPage.SetSizer(sizer)

			self.timelapsEnable = wx.CheckBox(self.camPage, -1, _("Enable timelapse movie recording"))
			self.timelapsSavePath = wx.TextCtrl(self.camPage, -1, os.path.expanduser('~/timelaps_' + datetime.datetime.now().strftime('%Y-%m-%d_%H:%M') + '.mpg'))
			sizer.Add(self.timelapsEnable, pos=(0, 0), span=(1, 2), flag=wx.EXPAND)
			sizer.Add(self.timelapsSavePath, pos=(1, 0), span=(1, 2), flag=wx.EXPAND)

			pages = self.cam.propertyPages()
			self.cam.buttons = [self.timelapsEnable, self.timelapsSavePath]
			for page in pages:
				button = wx.Button(self.camPage, -1, page)
				button.index = pages.index(page)
				sizer.Add(button, pos=(2, pages.index(page)))
				button.Bind(wx.EVT_BUTTON, self.OnPropertyPageButton)
				self.cam.buttons.append(button)

			self.campreviewEnable = wx.CheckBox(self.camPage, -1, _("Show preview"))
			sizer.Add(self.campreviewEnable, pos=(3, 0), span=(1, 2), flag=wx.EXPAND)

			self.camPreview = wx.Panel(self.camPage)
			sizer.Add(self.camPreview, pos=(4, 0), span=(1, 2), flag=wx.EXPAND)

			self.tabs.AddPage(self.camPage, _("Camera"))
			self.camPreview.timer = wx.Timer(self)
			self.Bind(wx.EVT_TIMER, self.OnCameraTimer, self.camPreview.timer)
			self.camPreview.timer.Start(500)
			self.camPreview.Bind(wx.EVT_ERASE_BACKGROUND, self.OnCameraEraseBackground)
		else:
			self.cam = None
Exemple #2
0
	def _webcamCheck(self):
		self.cam = webcam.webcam()
		if self.cam.hasCamera():
			self.camPage = wx.Panel(self.tabs)
			sizer = wx.GridBagSizer(2, 2)
			self.camPage.SetSizer(sizer)

			self.timelapsEnable = wx.CheckBox(self.camPage, -1, _("Enable timelapse movie recording"))
			self.timelapsSavePath = wx.TextCtrl(self.camPage, -1, os.path.expanduser('~/timelaps_' + datetime.datetime.now().strftime('%Y-%m-%d_%H:%M') + '.mpg'))
			sizer.Add(self.timelapsEnable, pos=(0, 0), span=(1, 2), flag=wx.EXPAND)
			sizer.Add(self.timelapsSavePath, pos=(1, 0), span=(1, 2), flag=wx.EXPAND)

			pages = self.cam.propertyPages()
			self.cam.buttons = [self.timelapsEnable, self.timelapsSavePath]
			for page in pages:
				button = wx.Button(self.camPage, -1, page)
				button.index = pages.index(page)
				sizer.Add(button, pos=(2, pages.index(page)))
				button.Bind(wx.EVT_BUTTON, self.OnWebcamPropertyPageButton)
				self.cam.buttons.append(button)

			self.campreviewEnable = wx.CheckBox(self.camPage, -1, _("Show preview"))
			sizer.Add(self.campreviewEnable, pos=(3, 0), span=(1, 2), flag=wx.EXPAND)

			self.camPreview = wx.Panel(self.camPage)
			sizer.Add(self.camPreview, pos=(4, 0), span=(1, 2), flag=wx.EXPAND)

			self.tabs.AddPage(self.camPage, _("Camera"))
			self.camPreview.timer = wx.Timer(self)
			self.Bind(wx.EVT_TIMER, self.OnCameraTimer, self.camPreview.timer)
			self.camPreview.timer.Start(500)
			self.camPreview.Bind(wx.EVT_ERASE_BACKGROUND, self.OnCameraEraseBackground)
		else:
			self.cam = None
Exemple #3
0
    def __init__(self, parent):
        super(webcamPhotoWindow, self).__init__(parent, title='YouMagine')
        p = wx.Panel(self)
        self.panel = p
        self.SetSizer(wx.BoxSizer())
        self.GetSizer().Add(p, 1, wx.EXPAND)

        self._cam = webcam.webcam()
        self._cam.takeNewImage(False)

        s = wx.GridBagSizer(3, 3)
        p.SetSizer(s)

        self._preview = wx.Panel(p)
        self._cameraSelect = wx.ComboBox(p,
                                         -1,
                                         self._cam.listCameras()[0],
                                         choices=self._cam.listCameras(),
                                         style=wx.CB_DROPDOWN | wx.CB_READONLY)
        self._takeImageButton = wx.Button(p, -1, 'Snap image')
        self._takeImageTimer = wx.Timer(self)

        s.Add(self._takeImageButton, pos=(1, 0), flag=wx.ALL, border=5)
        s.Add(self._cameraSelect, pos=(1, 1), flag=wx.ALL, border=5)
        s.Add(self._preview,
              pos=(0, 0),
              span=(1, 2),
              flag=wx.EXPAND | wx.ALL,
              border=5)

        if self._cam.getLastImage() is not None:
            self._preview.SetMinSize((self._cam.getLastImage().GetWidth(),
                                      self._cam.getLastImage().GetHeight()))
        else:
            self._preview.SetMinSize((640, 480))

        self._preview.Bind(wx.EVT_ERASE_BACKGROUND,
                           self.OnCameraEraseBackground)
        self.Bind(wx.EVT_BUTTON, self.OnTakeImage, self._takeImageButton)
        self.Bind(wx.EVT_TIMER, self.OnTakeImageTimer, self._takeImageTimer)
        self.Bind(wx.EVT_COMBOBOX, self.OnCameraChange, self._cameraSelect)

        self.Fit()
        self.Centre()

        self._takeImageTimer.Start(200)
Exemple #4
0
	def __init__(self, parent):
		super(webcamPhotoWindow, self).__init__(parent, title='YouMagine')
		p = wx.Panel(self)
		self.panel = p
		self.SetSizer(wx.BoxSizer())
		self.GetSizer().Add(p, 1, wx.EXPAND)

		self._cam = webcam.webcam()
		self._cam.takeNewImage(False)

		s = wx.GridBagSizer(3, 3)
		p.SetSizer(s)

		self._preview = wx.Panel(p)
		self._cameraSelect = wx.ComboBox(p, -1, self._cam.listCameras()[0], choices=self._cam.listCameras(), style=wx.CB_DROPDOWN|wx.CB_READONLY)
		self._takeImageButton = wx.Button(p, -1, 'Snap image')
		self._takeImageTimer = wx.Timer(self)

		s.Add(self._takeImageButton, pos=(1, 0), flag=wx.ALL, border=5)
		s.Add(self._cameraSelect, pos=(1, 1), flag=wx.ALL, border=5)
		s.Add(self._preview, pos=(0, 0), span=(1, 2), flag=wx.EXPAND|wx.ALL, border=5)

		if self._cam.getLastImage() is not None:
			self._preview.SetMinSize((self._cam.getLastImage().GetWidth(), self._cam.getLastImage().GetHeight()))
		else:
			self._preview.SetMinSize((640, 480))

		self._preview.Bind(wx.EVT_ERASE_BACKGROUND, self.OnCameraEraseBackground)
		self.Bind(wx.EVT_BUTTON, self.OnTakeImage, self._takeImageButton)
		self.Bind(wx.EVT_TIMER, self.OnTakeImageTimer, self._takeImageTimer)
		self.Bind(wx.EVT_COMBOBOX, self.OnCameraChange, self._cameraSelect)

		self.Fit()
		self.Centre()

		self._takeImageTimer.Start(200)
Exemple #5
0
	def __init__(self):
		super(printWindow, self).__init__(None, -1, title='Printing')
		self.machineCom = None
		self.gcode = None
		self.gcodeList = None
		self.sendList = []
		self.temp = None
		self.bedTemp = None
		self.bufferLineCount = 4
		self.sendCnt = 0
		self.feedrateRatioOuterWall = 1.0
		self.feedrateRatioInnerWall = 1.0
		self.feedrateRatioFill = 1.0
		self.feedrateRatioSupport = 1.0
		self.pause = False
		self.termHistory = []
		self.termHistoryIdx = 0

		self.cam = None
		if webcam.hasWebcamSupport():
			self.cam = webcam.webcam()
			if not self.cam.hasCamera():
				self.cam = None

		self.SetSizer(wx.BoxSizer())
		self.panel = wx.Panel(self)
		self.GetSizer().Add(self.panel, 1, flag=wx.EXPAND)
		self.sizer = wx.GridBagSizer(2, 2)
		self.panel.SetSizer(self.sizer)

		sb = wx.StaticBox(self.panel, label="Statistics")
		boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)

		self.powerWarningText = wx.StaticText(parent=self.panel,
			id=-1,
			label="Your computer is running on battery power.\nConnect your computer to AC power or your print might not finish.",
			style=wx.ALIGN_CENTER)
		self.powerWarningText.SetBackgroundColour('red')
		self.powerWarningText.SetForegroundColour('white')
		boxsizer.AddF(self.powerWarningText, flags=wx.SizerFlags().Expand().Border(wx.BOTTOM, 10))
		self.powerManagement = power.PowerManagement()
		self.powerWarningTimer = wx.Timer(self)
		self.Bind(wx.EVT_TIMER, self.OnPowerWarningChange, self.powerWarningTimer)
		self.OnPowerWarningChange(None)
		self.powerWarningTimer.Start(10000)

		self.statsText = wx.StaticText(self.panel, -1,
			"Filament: ####.##m #.##g\nEstimated print time: #####:##\nMachine state:\nDetecting baudrateXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
		boxsizer.Add(self.statsText, flag=wx.LEFT, border=5)

		self.sizer.Add(boxsizer, pos=(0, 0), span=(7, 1), flag=wx.EXPAND)

		self.connectButton = wx.Button(self.panel, -1, 'Connect')
		#self.loadButton = wx.Button(self.panel, -1, 'Load')
		self.printButton = wx.Button(self.panel, -1, 'Print')
		self.pauseButton = wx.Button(self.panel, -1, 'Pause')
		self.cancelButton = wx.Button(self.panel, -1, 'Cancel print')
		self.machineLogButton = wx.Button(self.panel, -1, 'Error log')
		self.progress = wx.Gauge(self.panel, -1)

		self.sizer.Add(self.connectButton, pos=(1, 1), flag=wx.EXPAND)
		#self.sizer.Add(self.loadButton, pos=(1,1), flag=wx.EXPAND)
		self.sizer.Add(self.printButton, pos=(2, 1), flag=wx.EXPAND)
		self.sizer.Add(self.pauseButton, pos=(3, 1), flag=wx.EXPAND)
		self.sizer.Add(self.cancelButton, pos=(4, 1), flag=wx.EXPAND)
		self.sizer.Add(self.machineLogButton, pos=(5, 1), flag=wx.EXPAND)
		self.sizer.Add(self.progress, pos=(7, 0), span=(1, 7), flag=wx.EXPAND)

		nb = wx.Notebook(self.panel)
		self.sizer.Add(nb, pos=(0, 2), span=(7, 4), flag=wx.EXPAND)

		self.temperaturePanel = wx.Panel(nb)
		sizer = wx.GridBagSizer(2, 2)
		self.temperaturePanel.SetSizer(sizer)

		self.temperatureSelect = wx.SpinCtrl(self.temperaturePanel, -1, '0', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS)
		self.temperatureSelect.SetRange(0, 400)
		self.bedTemperatureLabel = wx.StaticText(self.temperaturePanel, -1, "BedTemp:")
		self.bedTemperatureSelect = wx.SpinCtrl(self.temperaturePanel, -1, '0', size=(21 * 3, 21),
			style=wx.SP_ARROW_KEYS)
		self.bedTemperatureSelect.SetRange(0, 400)
		self.bedTemperatureLabel.Show(False)
		self.bedTemperatureSelect.Show(False)

		self.temperatureGraph = temperatureGraph(self.temperaturePanel)

		sizer.Add(wx.StaticText(self.temperaturePanel, -1, "Temp:"), pos=(0, 0))
		sizer.Add(self.temperatureSelect, pos=(0, 1))
		sizer.Add(self.bedTemperatureLabel, pos=(1, 0))
		sizer.Add(self.bedTemperatureSelect, pos=(1, 1))
		sizer.Add(self.temperatureGraph, pos=(2, 0), span=(1, 2), flag=wx.EXPAND)
		sizer.AddGrowableRow(2)
		sizer.AddGrowableCol(1)

		nb.AddPage(self.temperaturePanel, 'Temp')

		self.directControlPanel = wx.Panel(nb)

		sizer = wx.GridBagSizer(2, 2)
		self.directControlPanel.SetSizer(sizer)
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y100 F6000', 'G90'], 'print-move-y100.png'), pos=(0, 3))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y10 F6000', 'G90'], 'print-move-y10.png'), pos=(1, 3))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y1 F6000', 'G90'], 'print-move-y1.png'), pos=(2, 3))

		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-1 F6000', 'G90'], 'print-move-y-1.png'), pos=(4, 3))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-10 F6000', 'G90'], 'print-move-y-10.png'), pos=(5, 3))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-100 F6000', 'G90'], 'print-move-y-100.png'), pos=(6, 3))

		sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-100 F6000', 'G90'], 'print-move-x-100.png'), pos=(3, 0))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-10 F6000', 'G90'], 'print-move-x-10.png'), pos=(3, 1))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-1 F6000', 'G90'], 'print-move-x-1.png'), pos=(3, 2))

		sizer.Add(PrintCommandButton(self, ['G28 X0 Y0'], 'print-move-home.png'), pos=(3, 3))

		sizer.Add(PrintCommandButton(self, ['G91', 'G1 X1 F6000', 'G90'], 'print-move-x1.png'), pos=(3, 4))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 X10 F6000', 'G90'], 'print-move-x10.png'), pos=(3, 5))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 X100 F6000', 'G90'], 'print-move-x100.png'), pos=(3, 6))

		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z10 F200', 'G90'], 'print-move-z10.png'), pos=(0, 8))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z1 F200', 'G90'], 'print-move-z1.png'), pos=(1, 8))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z0.1 F200', 'G90'], 'print-move-z0.1.png'), pos=(2, 8))

		sizer.Add(PrintCommandButton(self, ['G28 Z0'], 'print-move-home.png'), pos=(3, 8))

		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-0.1 F200', 'G90'], 'print-move-z-0.1.png'), pos=(4, 8))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-1 F200', 'G90'], 'print-move-z-1.png'), pos=(5, 8))
		sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-10 F200', 'G90'], 'print-move-z-10.png'), pos=(6, 8))

		sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E2 F120'], 'extrude.png', size=(60, 20)), pos=(1, 10),
			span=(1, 3), flag=wx.EXPAND)
		sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E-2 F120'], 'retract.png', size=(60, 20)), pos=(2, 10),
			span=(1, 3), flag=wx.EXPAND)

		nb.AddPage(self.directControlPanel, 'Jog')

		self.speedPanel = wx.Panel(nb)
		sizer = wx.GridBagSizer(2, 2)
		self.speedPanel.SetSizer(sizer)

		self.outerWallSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS)
		self.outerWallSpeedSelect.SetRange(5, 1000)
		self.innerWallSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS)
		self.innerWallSpeedSelect.SetRange(5, 1000)
		self.fillSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS)
		self.fillSpeedSelect.SetRange(5, 1000)
		self.supportSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS)
		self.supportSpeedSelect.SetRange(5, 1000)

		sizer.Add(wx.StaticText(self.speedPanel, -1, "Outer wall:"), pos=(0, 0))
		sizer.Add(self.outerWallSpeedSelect, pos=(0, 1))
		sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(0, 2))
		sizer.Add(wx.StaticText(self.speedPanel, -1, "Inner wall:"), pos=(1, 0))
		sizer.Add(self.innerWallSpeedSelect, pos=(1, 1))
		sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(1, 2))
		sizer.Add(wx.StaticText(self.speedPanel, -1, "Fill:"), pos=(2, 0))
		sizer.Add(self.fillSpeedSelect, pos=(2, 1))
		sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(2, 2))
		sizer.Add(wx.StaticText(self.speedPanel, -1, "Support:"), pos=(3, 0))
		sizer.Add(self.supportSpeedSelect, pos=(3, 1))
		sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(3, 2))

		nb.AddPage(self.speedPanel, 'Speed')

		self.termPanel = wx.Panel(nb)
		sizer = wx.GridBagSizer(2, 2)
		self.termPanel.SetSizer(sizer)

		f = wx.Font(8, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False)
		self.termLog = wx.TextCtrl(self.termPanel, style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
		self.termLog.SetFont(f)
		self.termLog.SetEditable(0)
		self.termInput = wx.TextCtrl(self.termPanel, style=wx.TE_PROCESS_ENTER)
		self.termInput.SetFont(f)

		sizer.Add(self.termLog, pos=(0, 0), flag=wx.EXPAND)
		sizer.Add(self.termInput, pos=(1, 0), flag=wx.EXPAND)
		sizer.AddGrowableCol(0)
		sizer.AddGrowableRow(0)

		nb.AddPage(self.termPanel, 'Term')

		if self.cam != None:
			self.camPage = wx.Panel(nb)
			sizer = wx.GridBagSizer(2, 2)
			self.camPage.SetSizer(sizer)

			self.timelapsEnable = wx.CheckBox(self.camPage, -1, 'Enable timelapse movie recording')
			sizer.Add(self.timelapsEnable, pos=(0, 0), span=(1, 2), flag=wx.EXPAND)

			pages = self.cam.propertyPages()
			self.cam.buttons = [self.timelapsEnable]
			for page in pages:
				button = wx.Button(self.camPage, -1, page)
				button.index = pages.index(page)
				sizer.Add(button, pos=(1, pages.index(page)))
				button.Bind(wx.EVT_BUTTON, self.OnPropertyPageButton)
				self.cam.buttons.append(button)

			self.campreviewEnable = wx.CheckBox(self.camPage, -1, 'Show preview')
			sizer.Add(self.campreviewEnable, pos=(2, 0), span=(1, 2), flag=wx.EXPAND)

			self.camPreview = wx.Panel(self.camPage)
			sizer.Add(self.camPreview, pos=(3, 0), span=(1, 2), flag=wx.EXPAND)

			nb.AddPage(self.camPage, 'Camera')
			self.camPreview.timer = wx.Timer(self)
			self.Bind(wx.EVT_TIMER, self.OnCameraTimer, self.camPreview.timer)
			self.camPreview.timer.Start(500)
			self.camPreview.Bind(wx.EVT_ERASE_BACKGROUND, self.OnCameraEraseBackground)

		self.sizer.AddGrowableRow(6)
		self.sizer.AddGrowableCol(3)

		self.Bind(wx.EVT_CLOSE, self.OnClose)
		self.connectButton.Bind(wx.EVT_BUTTON, self.OnConnect)
		#self.loadButton.Bind(wx.EVT_BUTTON, self.OnLoad)
		self.printButton.Bind(wx.EVT_BUTTON, self.OnPrint)
		self.pauseButton.Bind(wx.EVT_BUTTON, self.OnPause)
		self.cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel)
		self.machineLogButton.Bind(wx.EVT_BUTTON, self.OnMachineLog)

		self.Bind(wx.EVT_SPINCTRL, self.OnTempChange, self.temperatureSelect)
		self.Bind(wx.EVT_SPINCTRL, self.OnBedTempChange, self.bedTemperatureSelect)

		self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.outerWallSpeedSelect)
		self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.innerWallSpeedSelect)
		self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.fillSpeedSelect)
		self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.supportSpeedSelect)
		self.Bind(wx.EVT_TEXT_ENTER, self.OnTermEnterLine, self.termInput)
		self.termInput.Bind(wx.EVT_CHAR, self.OnTermKey)

		self.Layout()
		self.Fit()
		self.Centre()

		self.statsText.SetMinSize(self.statsText.GetSize())

		self.UpdateButtonStates()
Exemple #6
0
    def __init__(self):
        super(printWindow, self).__init__(None, -1, title='Printing')
        self.machineCom = None
        self.gcode = None
        self.gcodeList = None
        self.sendList = []
        self.temp = None
        self.bedTemp = None
        self.bufferLineCount = 4
        self.sendCnt = 0
        self.feedrateRatioOuterWall = 1.0
        self.feedrateRatioInnerWall = 1.0
        self.feedrateRatioFill = 1.0
        self.feedrateRatioSupport = 1.0
        self.pause = False
        self.termHistory = []
        self.termHistoryIdx = 0

        self.cam = None
        if webcam.hasWebcamSupport():
            self.cam = webcam.webcam()
            if not self.cam.hasCamera():
                self.cam = None

        self.SetSizer(wx.BoxSizer())
        self.panel = wx.Panel(self)
        self.GetSizer().Add(self.panel, 1, flag=wx.EXPAND)
        self.sizer = wx.GridBagSizer(2, 2)
        self.panel.SetSizer(self.sizer)

        sb = wx.StaticBox(self.panel, label="Statistics")
        boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)

        self.powerWarningText = wx.StaticText(
            parent=self.panel,
            id=-1,
            label=
            "Your computer is running on battery power.\nConnect your computer to AC power or your print might not finish.",
            style=wx.ALIGN_CENTER)
        self.powerWarningText.SetBackgroundColour('red')
        self.powerWarningText.SetForegroundColour('white')
        boxsizer.AddF(self.powerWarningText,
                      flags=wx.SizerFlags().Expand().Border(wx.BOTTOM, 10))
        self.powerManagement = power.PowerManagement()
        self.powerWarningTimer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnPowerWarningChange,
                  self.powerWarningTimer)
        self.OnPowerWarningChange(None)
        self.powerWarningTimer.Start(10000)

        self.statsText = wx.StaticText(
            self.panel, -1,
            "Filament: ####.##m #.##g\nEstimated print time: #####:##\nMachine state:\nDetecting baudrateXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        )
        boxsizer.Add(self.statsText, flag=wx.LEFT, border=5)

        self.sizer.Add(boxsizer, pos=(0, 0), span=(7, 1), flag=wx.EXPAND)

        self.connectButton = wx.Button(self.panel, -1, 'Connect')
        #self.loadButton = wx.Button(self.panel, -1, 'Load')
        self.printButton = wx.Button(self.panel, -1, 'Print')
        self.pauseButton = wx.Button(self.panel, -1, 'Pause')
        self.cancelButton = wx.Button(self.panel, -1, 'Cancel print')
        self.machineLogButton = wx.Button(self.panel, -1, 'Error log')
        self.progress = wx.Gauge(self.panel, -1)

        self.sizer.Add(self.connectButton, pos=(1, 1), flag=wx.EXPAND)
        #self.sizer.Add(self.loadButton, pos=(1,1), flag=wx.EXPAND)
        self.sizer.Add(self.printButton, pos=(2, 1), flag=wx.EXPAND)
        self.sizer.Add(self.pauseButton, pos=(3, 1), flag=wx.EXPAND)
        self.sizer.Add(self.cancelButton, pos=(4, 1), flag=wx.EXPAND)
        self.sizer.Add(self.machineLogButton, pos=(5, 1), flag=wx.EXPAND)
        self.sizer.Add(self.progress, pos=(7, 0), span=(1, 7), flag=wx.EXPAND)

        nb = wx.Notebook(self.panel)
        self.sizer.Add(nb, pos=(0, 2), span=(7, 4), flag=wx.EXPAND)

        self.temperaturePanel = wx.Panel(nb)
        sizer = wx.GridBagSizer(2, 2)
        self.temperaturePanel.SetSizer(sizer)

        self.temperatureSelect = wx.SpinCtrl(self.temperaturePanel,
                                             -1,
                                             '0',
                                             size=(21 * 3, 21),
                                             style=wx.SP_ARROW_KEYS)
        self.temperatureSelect.SetRange(0, 400)
        self.bedTemperatureLabel = wx.StaticText(self.temperaturePanel, -1,
                                                 "BedTemp:")
        self.bedTemperatureSelect = wx.SpinCtrl(self.temperaturePanel,
                                                -1,
                                                '0',
                                                size=(21 * 3, 21),
                                                style=wx.SP_ARROW_KEYS)
        self.bedTemperatureSelect.SetRange(0, 400)
        self.bedTemperatureLabel.Show(False)
        self.bedTemperatureSelect.Show(False)

        self.temperatureGraph = temperatureGraph(self.temperaturePanel)

        sizer.Add(wx.StaticText(self.temperaturePanel, -1, "Temp:"),
                  pos=(0, 0))
        sizer.Add(self.temperatureSelect, pos=(0, 1))
        sizer.Add(self.bedTemperatureLabel, pos=(1, 0))
        sizer.Add(self.bedTemperatureSelect, pos=(1, 1))
        sizer.Add(self.temperatureGraph,
                  pos=(2, 0),
                  span=(1, 2),
                  flag=wx.EXPAND)
        sizer.AddGrowableRow(2)
        sizer.AddGrowableCol(1)

        nb.AddPage(self.temperaturePanel, 'Temp')

        self.directControlPanel = wx.Panel(nb)

        sizer = wx.GridBagSizer(2, 2)
        self.directControlPanel.SetSizer(sizer)
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y100 F6000', 'G90'],
                                     'print-move-y100.png'),
                  pos=(0, 3))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y10 F6000', 'G90'],
                                     'print-move-y10.png'),
                  pos=(1, 3))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y1 F6000', 'G90'],
                                     'print-move-y1.png'),
                  pos=(2, 3))

        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-1 F6000', 'G90'],
                                     'print-move-y-1.png'),
                  pos=(4, 3))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-10 F6000', 'G90'],
                                     'print-move-y-10.png'),
                  pos=(5, 3))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-100 F6000', 'G90'],
                                     'print-move-y-100.png'),
                  pos=(6, 3))

        sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-100 F6000', 'G90'],
                                     'print-move-x-100.png'),
                  pos=(3, 0))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-10 F6000', 'G90'],
                                     'print-move-x-10.png'),
                  pos=(3, 1))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-1 F6000', 'G90'],
                                     'print-move-x-1.png'),
                  pos=(3, 2))

        sizer.Add(PrintCommandButton(self, ['G28 X0 Y0'],
                                     'print-move-home.png'),
                  pos=(3, 3))

        sizer.Add(PrintCommandButton(self, ['G91', 'G1 X1 F6000', 'G90'],
                                     'print-move-x1.png'),
                  pos=(3, 4))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 X10 F6000', 'G90'],
                                     'print-move-x10.png'),
                  pos=(3, 5))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 X100 F6000', 'G90'],
                                     'print-move-x100.png'),
                  pos=(3, 6))

        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z10 F200', 'G90'],
                                     'print-move-z10.png'),
                  pos=(0, 8))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z1 F200', 'G90'],
                                     'print-move-z1.png'),
                  pos=(1, 8))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z0.1 F200', 'G90'],
                                     'print-move-z0.1.png'),
                  pos=(2, 8))

        sizer.Add(PrintCommandButton(self, ['G28 Z0'], 'print-move-home.png'),
                  pos=(3, 8))

        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-0.1 F200', 'G90'],
                                     'print-move-z-0.1.png'),
                  pos=(4, 8))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-1 F200', 'G90'],
                                     'print-move-z-1.png'),
                  pos=(5, 8))
        sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-10 F200', 'G90'],
                                     'print-move-z-10.png'),
                  pos=(6, 8))

        sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E2 F120'],
                                     'extrude.png',
                                     size=(60, 20)),
                  pos=(1, 10),
                  span=(1, 3),
                  flag=wx.EXPAND)
        sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E-2 F120'],
                                     'retract.png',
                                     size=(60, 20)),
                  pos=(2, 10),
                  span=(1, 3),
                  flag=wx.EXPAND)

        nb.AddPage(self.directControlPanel, 'Jog')

        self.speedPanel = wx.Panel(nb)
        sizer = wx.GridBagSizer(2, 2)
        self.speedPanel.SetSizer(sizer)

        self.outerWallSpeedSelect = wx.SpinCtrl(self.speedPanel,
                                                -1,
                                                '100',
                                                size=(21 * 3, 21),
                                                style=wx.SP_ARROW_KEYS)
        self.outerWallSpeedSelect.SetRange(5, 1000)
        self.innerWallSpeedSelect = wx.SpinCtrl(self.speedPanel,
                                                -1,
                                                '100',
                                                size=(21 * 3, 21),
                                                style=wx.SP_ARROW_KEYS)
        self.innerWallSpeedSelect.SetRange(5, 1000)
        self.fillSpeedSelect = wx.SpinCtrl(self.speedPanel,
                                           -1,
                                           '100',
                                           size=(21 * 3, 21),
                                           style=wx.SP_ARROW_KEYS)
        self.fillSpeedSelect.SetRange(5, 1000)
        self.supportSpeedSelect = wx.SpinCtrl(self.speedPanel,
                                              -1,
                                              '100',
                                              size=(21 * 3, 21),
                                              style=wx.SP_ARROW_KEYS)
        self.supportSpeedSelect.SetRange(5, 1000)

        sizer.Add(wx.StaticText(self.speedPanel, -1, "Outer wall:"),
                  pos=(0, 0))
        sizer.Add(self.outerWallSpeedSelect, pos=(0, 1))
        sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(0, 2))
        sizer.Add(wx.StaticText(self.speedPanel, -1, "Inner wall:"),
                  pos=(1, 0))
        sizer.Add(self.innerWallSpeedSelect, pos=(1, 1))
        sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(1, 2))
        sizer.Add(wx.StaticText(self.speedPanel, -1, "Fill:"), pos=(2, 0))
        sizer.Add(self.fillSpeedSelect, pos=(2, 1))
        sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(2, 2))
        sizer.Add(wx.StaticText(self.speedPanel, -1, "Support:"), pos=(3, 0))
        sizer.Add(self.supportSpeedSelect, pos=(3, 1))
        sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(3, 2))

        nb.AddPage(self.speedPanel, 'Speed')

        self.termPanel = wx.Panel(nb)
        sizer = wx.GridBagSizer(2, 2)
        self.termPanel.SetSizer(sizer)

        f = wx.Font(8, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL, False)
        self.termLog = wx.TextCtrl(self.termPanel,
                                   style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
        self.termLog.SetFont(f)
        self.termLog.SetEditable(0)
        self.termInput = wx.TextCtrl(self.termPanel, style=wx.TE_PROCESS_ENTER)
        self.termInput.SetFont(f)

        sizer.Add(self.termLog, pos=(0, 0), flag=wx.EXPAND)
        sizer.Add(self.termInput, pos=(1, 0), flag=wx.EXPAND)
        sizer.AddGrowableCol(0)
        sizer.AddGrowableRow(0)

        nb.AddPage(self.termPanel, 'Term')

        if self.cam is not None:
            self.camPage = wx.Panel(nb)
            sizer = wx.GridBagSizer(2, 2)
            self.camPage.SetSizer(sizer)

            self.timelapsEnable = wx.CheckBox(
                self.camPage, -1, 'Enable timelapse movie recording')
            sizer.Add(self.timelapsEnable,
                      pos=(0, 0),
                      span=(1, 2),
                      flag=wx.EXPAND)

            pages = self.cam.propertyPages()
            self.cam.buttons = [self.timelapsEnable]
            for page in pages:
                button = wx.Button(self.camPage, -1, page)
                button.index = pages.index(page)
                sizer.Add(button, pos=(1, pages.index(page)))
                button.Bind(wx.EVT_BUTTON, self.OnPropertyPageButton)
                self.cam.buttons.append(button)

            self.campreviewEnable = wx.CheckBox(self.camPage, -1,
                                                'Show preview')
            sizer.Add(self.campreviewEnable,
                      pos=(2, 0),
                      span=(1, 2),
                      flag=wx.EXPAND)

            self.camPreview = wx.Panel(self.camPage)
            sizer.Add(self.camPreview, pos=(3, 0), span=(1, 2), flag=wx.EXPAND)

            nb.AddPage(self.camPage, 'Camera')
            self.camPreview.timer = wx.Timer(self)
            self.Bind(wx.EVT_TIMER, self.OnCameraTimer, self.camPreview.timer)
            self.camPreview.timer.Start(500)
            self.camPreview.Bind(wx.EVT_ERASE_BACKGROUND,
                                 self.OnCameraEraseBackground)

        self.sizer.AddGrowableRow(6)
        self.sizer.AddGrowableCol(3)

        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.connectButton.Bind(wx.EVT_BUTTON, self.OnConnect)
        #self.loadButton.Bind(wx.EVT_BUTTON, self.OnLoad)
        self.printButton.Bind(wx.EVT_BUTTON, self.OnPrint)
        self.pauseButton.Bind(wx.EVT_BUTTON, self.OnPause)
        self.cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel)
        self.machineLogButton.Bind(wx.EVT_BUTTON, self.OnMachineLog)

        self.Bind(wx.EVT_SPINCTRL, self.OnTempChange, self.temperatureSelect)
        self.Bind(wx.EVT_SPINCTRL, self.OnBedTempChange,
                  self.bedTemperatureSelect)

        self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange,
                  self.outerWallSpeedSelect)
        self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange,
                  self.innerWallSpeedSelect)
        self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.fillSpeedSelect)
        self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.supportSpeedSelect)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnTermEnterLine, self.termInput)
        self.termInput.Bind(wx.EVT_CHAR, self.OnTermKey)

        self.Layout()
        self.Fit()
        self.Centre()

        self.statsText.SetMinSize(self.statsText.GetSize())

        self.UpdateButtonStates()