def createGui(self): self.panel = wx.Panel(self, -1, size=self.size) self.panel.SetBackgroundColour(self.settings.bgcolor) self.mainsizer = wx.BoxSizer(wx.VERTICAL) self.uppersizer = MainToolbar(self) self.lowersizer = wx.BoxSizer(wx.HORIZONTAL) self.leftpane = LeftPane(self) self.lowersizer.Add(self.leftpane) self.hiddensizer = wx.BoxSizer(wx.HORIZONTAL) self.lowersizer.Add(self.hiddensizer) self.lowersizer.Hide(self.hiddensizer) #self.vizlogsizer = wx.BoxSizer(wx.VERTICAL) self.vizlogsizer = wx.GridBagSizer(hgap=5, vgap=5) vp = VizPane(self) #self.hiddensizer.Add(vp) #, 1, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL) #self.hiddensizer.Hide(vp) self.leftpane.Add(vp, pos=(2, 5), span=(4, 1)) self.tempdisp = wx.StaticText(self.panel, wx.ID_ANY, "", size=(300, 15)) self.graph = Graph(self, wx.ID_ANY) #self.kb = KeyboardSizer(self) self.vizlogsizer.Add(self.graph, pos=(0, 0)) # wx.ID_ANY) #self.hiddensizer.Add(self.tempdisp) self.vizlogsizer.Add(self.tempdisp, pos=(1, 0)) self.vizlogsizer.Add(LogPane(self), pos=(2, 0)) #self.vizlogsizer.Add(self.kb, pos=(0,0)) self.lowersizer.Add(self.vizlogsizer) #,wx.ID_ANY, wx.EXPAND) self.centersizer = wx.GridBagSizer() self.lowersizer.Add(self.centersizer) self.mainsizer.Add(self.uppersizer) self.mainsizer.Add(self.lowersizer) #, 1, wx.EXPAND) self.panel.SetSizer(self.mainsizer) self.status = self.CreateStatusBar() self.status.SetStatusText(_("Нет соединения с принтером")) self.panel.Bind(wx.EVT_MOUSE_EVENTS, self.editbutton) self.Bind(wx.EVT_CLOSE, self.kill) self.mainsizer.Layout() self.mainsizer.Fit(self) # disable all printer controls until we connect to a printer self.pausebtn.Disable() self.recoverbtn.Disable() for i in self.printerControls: i.Disable() #self.panel.Fit() self.cbuttons_reload() self.graph.StartPlotting(1000)
def add_extra_controls(self, root, parentpanel, extra_buttons=None): standalone_mode = extra_buttons is not None base_line = 1 if standalone_mode else 2 root.monitorbox = wx.CheckBox(parentpanel, -1, _("Watch")) root.monitorbox.SetValue(bool(root.settings.monitor)) root.monitorbox.SetToolTip(wx.ToolTip(_("Monitor Temperatures in Graph"))) if standalone_mode: self.Add(root.monitorbox, pos=(0, 3), span=(1, 3)) else: self.Add(root.monitorbox, pos=(base_line + 1, 5)) root.monitorbox.Bind(wx.EVT_CHECKBOX, root.setmonitor) self.Add(wx.StaticText(parentpanel, -1, _("Heat:")), pos=(base_line + 0, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) htemp_choices = [ root.temps[i] + " (" + i + ")" for i in sorted(root.temps.keys(), key=lambda x: root.temps[x]) ] root.settoff = make_button(parentpanel, _("Off"), lambda e: root.do_settemp("off"), _("Switch Hotend Off"), size=(38, -1), style=wx.BU_EXACTFIT) root.printerControls.append(root.settoff) self.Add(root.settoff, pos=(base_line + 0, 2), span=(1, 1)) if root.settings.last_temperature not in map(float, root.temps.values()): htemp_choices = [str(root.settings.last_temperature)] + htemp_choices root.htemp = wx.ComboBox(parentpanel, -1, choices=htemp_choices, style=wx.CB_DROPDOWN, size=(80, -1)) root.htemp.SetToolTip(wx.ToolTip(_("Select Temperature for Hotend"))) root.htemp.Bind(wx.EVT_COMBOBOX, root.htemp_change) self.Add(root.htemp, pos=(base_line + 0, 3), span=(1, 1)) root.settbtn = make_button(parentpanel, _("Set"), root.do_settemp, _("Switch Hotend On"), size=(38, -1), style=wx.BU_EXACTFIT) root.printerControls.append(root.settbtn) self.Add(root.settbtn, pos=(base_line + 0, 4), span=(1, 1)) self.Add(wx.StaticText(parentpanel, -1, _("Bed:")), pos=(base_line + 1, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) btemp_choices = [ root.bedtemps[i] + " (" + i + ")" for i in sorted(root.bedtemps.keys(), key=lambda x: root.temps[x]) ] root.setboff = make_button(parentpanel, _("Off"), lambda e: root.do_bedtemp("off"), _("Switch Heated Bed Off"), size=(38, -1), style=wx.BU_EXACTFIT) root.printerControls.append(root.setboff) self.Add(root.setboff, pos=(base_line + 1, 2), span=(1, 1)) if root.settings.last_bed_temperature not in map(float, root.bedtemps.values()): btemp_choices = [str(root.settings.last_bed_temperature) ] + btemp_choices root.btemp = wx.ComboBox(parentpanel, -1, choices=btemp_choices, style=wx.CB_DROPDOWN, size=(80, -1)) root.btemp.SetToolTip(wx.ToolTip(_("Select Temperature for Heated Bed"))) root.btemp.Bind(wx.EVT_COMBOBOX, root.btemp_change) self.Add(root.btemp, pos=(base_line + 1, 3), span=(1, 1)) root.setbbtn = make_button(parentpanel, _("Set"), root.do_bedtemp, _("Switch Heated Bed On"), size=(38, -1), style=wx.BU_EXACTFIT) root.printerControls.append(root.setbbtn) self.Add(root.setbbtn, pos=(base_line + 1, 4), span=(1, 1)) root.btemp.SetValue(str(root.settings.last_bed_temperature)) root.htemp.SetValue(str(root.settings.last_temperature)) ## added for an error where only the bed would get (pla) or (abs). #This ensures, if last temp is a default pla or abs, it will be marked so. # if it is not, then a (user) remark is added. This denotes a manual entry for i in btemp_choices: if i.split()[0] == str(root.settings.last_bed_temperature).split( '.')[0] or i.split()[0] == str( root.settings.last_bed_temperature): root.btemp.SetValue(i) for i in htemp_choices: if i.split()[0] == str(root.settings.last_temperature).split( '.')[0] or i.split()[0] == str(root.settings.last_temperature): root.htemp.SetValue(i) if '(' not in root.btemp.Value: root.btemp.SetValue(root.btemp.Value + ' (user)') if '(' not in root.htemp.Value: root.htemp.SetValue(root.htemp.Value + ' (user)') root.tempdisp = wx.StaticText(parentpanel, -1, "") if not extra_buttons: ebuttonspanel = root.newPanel(parentpanel) ebuttonssizer = wx.BoxSizer(wx.HORIZONTAL) if root.settings.extruders > 1: ebuttonssizer.Add(wx.StaticText(ebuttonspanel, -1, _("Tool:")), flag=wx.ALIGN_CENTER) if root.settings.extruders == 2: root.extrudersel = wx.Button(ebuttonspanel, -1, "0", style=wx.BU_EXACTFIT) root.extrudersel.SetToolTip( wx.ToolTip(_("Click to switch current extruder"))) def extrudersel_cb(event): if root.extrudersel.GetLabel() == "1": new = "0" else: new = "1" root.extrudersel.SetLabel(new) root.tool_change(event) root.extrudersel.Bind(wx.EVT_BUTTON, extrudersel_cb) root.extrudersel.GetValue = root.extrudersel.GetLabel root.extrudersel.SetValue = root.extrudersel.SetLabel else: choices = [str(i) for i in range(0, root.settings.extruders)] root.extrudersel = wx.ComboBox(ebuttonspanel, -1, choices=choices, style=wx.CB_DROPDOWN | wx.CB_READONLY, size=(50, -1)) root.extrudersel.SetToolTip( wx.ToolTip(_("Select current extruder"))) root.extrudersel.SetValue(choices[0]) root.extrudersel.Bind(wx.EVT_COMBOBOX, root.tool_change) root.printerControls.append(root.extrudersel) ebuttonssizer.Add(root.extrudersel) ebuttonspanel.SetSizer(ebuttonssizer) self.Add(ebuttonspanel, pos=(base_line + 2, 0), span=(1, 5), flag=wx.EXPAND) esettingspanel = root.newPanel(parentpanel) esettingssizer = wx.BoxSizer(wx.HORIZONTAL) root.edist = wx.SpinCtrl(esettingspanel, -1, str(root.settings.last_extrusion), min=0, max=1000, size=(70, -1)) root.edist.SetBackgroundColour((225, 200, 200)) root.edist.SetForegroundColour("black") root.edist.Bind(wx.EVT_SPINCTRL, root.setfeeds) root.edist.Bind(wx.EVT_TEXT, root.setfeeds) esettingssizer.Add(root.edist, flag=wx.ALIGN_CENTER | wx.RIGHT, border=5) esettingssizer.Add(wx.StaticText(esettingspanel, -1, _("mm @")), flag=wx.ALIGN_CENTER | wx.RIGHT, border=5) root.edist.SetToolTip(wx.ToolTip(_("Amount to Extrude or Retract (mm)"))) root.efeedc = wx.SpinCtrl(esettingspanel, -1, str(root.settings.e_feedrate), min=0, max=50000, size=(70, -1)) root.efeedc.SetToolTip(wx.ToolTip(_("Extrude / Retract speed (mm/min)"))) root.efeedc.SetBackgroundColour((225, 200, 200)) root.efeedc.SetForegroundColour("black") root.efeedc.Bind(wx.EVT_SPINCTRL, root.setfeeds) root.efeedc.Bind(wx.EVT_TEXT, root.setfeeds) esettingssizer.Add(root.efeedc, flag=wx.ALIGN_CENTER | wx.RIGHT, border=5) esettingssizer.Add(wx.StaticText(esettingspanel, -1, _("mm/\nmin")), flag=wx.ALIGN_CENTER) esettingspanel.SetSizer(esettingssizer) self.Add(esettingspanel, pos=(base_line + 3, 0), span=(1, 5)) gauges_base_line = base_line + 8 if standalone_mode else base_line + 5 if root.display_gauges: root.hottgauge = TempGauge(parentpanel, size=(-1, 24), title=_("Heater:"), maxval=300) self.Add(root.hottgauge, pos=(gauges_base_line + 0, 0), span=(1, 6), flag=wx.EXPAND) root.bedtgauge = TempGauge(parentpanel, size=(-1, 24), title=_("Bed:"), maxval=150) self.Add(root.bedtgauge, pos=(gauges_base_line + 1, 0), span=(1, 6), flag=wx.EXPAND) def hotendgauge_scroll_setpoint(e): rot = e.GetWheelRotation() if rot > 0: root.do_settemp(str(root.hsetpoint + 1)) elif rot < 0: root.do_settemp(str(max(0, root.hsetpoint - 1))) def bedgauge_scroll_setpoint(e): rot = e.GetWheelRotation() if rot > 0: root.do_settemp(str(root.bsetpoint + 1)) elif rot < 0: root.do_settemp(str(max(0, root.bsetpoint - 1))) root.hottgauge.Bind(wx.EVT_MOUSEWHEEL, hotendgauge_scroll_setpoint) root.bedtgauge.Bind(wx.EVT_MOUSEWHEEL, bedgauge_scroll_setpoint) self.Add(root.tempdisp, pos=(gauges_base_line + 2, 0), span=(1, 6)) else: self.Add(root.tempdisp, pos=(gauges_base_line + 0, 0), span=(1, 6)) if root.display_graph: root.graph = Graph(parentpanel, wx.ID_ANY, root) if standalone_mode: self.Add(root.graph, pos=(base_line + 5, 0), span=(3, 6)) else: self.Add(root.graph, pos=(base_line + 2, 5), span=(3, 1)) root.graph.Bind(wx.EVT_LEFT_DOWN, root.graph.showwin) if extra_buttons: pos_mapping = { (2, 5): (0, 0), (4, 0): (3, 0), (4, 2): (3, 2), } span_mapping = { (2, 5): (1, 3), (4, 0): (1, 2), (4, 2): (1, 3), } for i in extra_buttons: btn = extra_buttons[i] self.Add(btn, pos=pos_mapping[i.pos], span=span_mapping[i.pos], flag=wx.EXPAND) else: for i in root.cpbuttons: if not i.pos or i.pos[0] != 4: continue btn = make_custom_button(root, ebuttonspanel, i, style=wx.BU_EXACTFIT) ebuttonssizer.Add(btn, 1, flag=wx.EXPAND)
class MainWindow(wx.Frame): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) # this list will contain all controls that should be only enabled # when we're connected to a printer self.printerControls = [] def fullscreen(self, event): self.ShowFullScreen(not self.IsFullScreen()) def createGui(self): self.panel = wx.Panel(self, -1, size=self.size) self.panel.SetBackgroundColour(self.settings.bgcolor) self.mainsizer = wx.BoxSizer(wx.VERTICAL) self.uppersizer = MainToolbar(self) self.lowersizer = wx.BoxSizer(wx.HORIZONTAL) self.leftpane = LeftPane(self) self.lowersizer.Add(self.leftpane) self.hiddensizer = wx.BoxSizer(wx.HORIZONTAL) self.lowersizer.Add(self.hiddensizer) self.lowersizer.Hide(self.hiddensizer) #self.vizlogsizer = wx.BoxSizer(wx.VERTICAL) self.vizlogsizer = wx.GridBagSizer(hgap=5, vgap=5) vp = VizPane(self) #self.hiddensizer.Add(vp) #, 1, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL) #self.hiddensizer.Hide(vp) self.leftpane.Add(vp, pos=(2, 5), span=(4, 1)) self.tempdisp = wx.StaticText(self.panel, wx.ID_ANY, "", size=(300, 15)) self.graph = Graph(self, wx.ID_ANY) #self.kb = KeyboardSizer(self) self.vizlogsizer.Add(self.graph, pos=(0, 0)) # wx.ID_ANY) #self.hiddensizer.Add(self.tempdisp) self.vizlogsizer.Add(self.tempdisp, pos=(1, 0)) self.vizlogsizer.Add(LogPane(self), pos=(2, 0)) #self.vizlogsizer.Add(self.kb, pos=(0,0)) self.lowersizer.Add(self.vizlogsizer) #,wx.ID_ANY, wx.EXPAND) self.centersizer = wx.GridBagSizer() self.lowersizer.Add(self.centersizer) self.mainsizer.Add(self.uppersizer) self.mainsizer.Add(self.lowersizer) #, 1, wx.EXPAND) self.panel.SetSizer(self.mainsizer) self.status = self.CreateStatusBar() self.status.SetStatusText(_("Нет соединения с принтером")) self.panel.Bind(wx.EVT_MOUSE_EVENTS, self.editbutton) self.Bind(wx.EVT_CLOSE, self.kill) self.mainsizer.Layout() self.mainsizer.Fit(self) # disable all printer controls until we connect to a printer self.pausebtn.Disable() self.recoverbtn.Disable() for i in self.printerControls: i.Disable() #self.panel.Fit() self.cbuttons_reload() self.graph.StartPlotting(1000)
def __init__(self, root): super(LeftPane, self).__init__() llts = wx.BoxSizer(wx.HORIZONTAL) self.Add(llts, pos=(0, 0), span=(1, 6)) self.xyzsizer = XYZControlsSizer(root) self.Add(self.xyzsizer, pos=(1, 0), span=(1, 6), flag=wx.ALIGN_CENTER) for i in root.cpbuttons: btn = make_button(root.panel, i.label, root.procbutton, i.tooltip, style=wx.BU_EXACTFIT) btn.SetBackgroundColour(i.background) btn.SetForegroundColour("black") btn.properties = i root.btndict[i.command] = btn root.printerControls.append(btn) if i.pos == None: if i.span == 0: llts.Add(btn) else: self.Add(btn, pos=i.pos, span=i.span) root.xyfeedc = wx.SpinCtrl(root.panel, -1, str(root.settings.xy_feedrate), min=0, max=50000, size=(70, -1)) root.xyfeedc.SetToolTip( wx.ToolTip("Set Maximum Speed for X & Y axes (mm/min)")) llts.Add(wx.StaticText(root.panel, -1, _("XY:")), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) llts.Add(root.xyfeedc) llts.Add(wx.StaticText(root.panel, -1, _("mm/min Z:")), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) root.zfeedc = wx.SpinCtrl(root.panel, -1, str(root.settings.z_feedrate), min=0, max=50000, size=(70, -1)) root.zfeedc.SetToolTip( wx.ToolTip("Set Maximum Speed for Z axis (mm/min)")) llts.Add(root.zfeedc, ) root.monitorbox = wx.CheckBox(root.panel, -1, _("Watch")) root.monitorbox.SetToolTip(wx.ToolTip("Monitor Temperatures in Graph")) self.Add(root.monitorbox, pos=(3, 5)) root.monitorbox.Bind(wx.EVT_CHECKBOX, root.setmonitor) self.Add(wx.StaticText(root.panel, -1, _("Heat:")), pos=(2, 0), span=(1, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) htemp_choices = [ root.temps[i] + " (" + i + ")" for i in sorted(root.temps.keys(), key=lambda x: root.temps[x]) ] root.settoff = make_button(root.panel, _("Off"), lambda e: root.do_settemp("off"), _("Switch Hotend Off"), size=(36, -1), style=wx.BU_EXACTFIT) root.printerControls.append(root.settoff) self.Add(root.settoff, pos=(2, 1), span=(1, 1)) if root.settings.last_temperature not in map(float, root.temps.values()): htemp_choices = [str(root.settings.last_temperature) ] + htemp_choices root.htemp = wx.ComboBox(root.panel, -1, choices=htemp_choices, style=wx.CB_DROPDOWN, size=(80, -1)) root.htemp.SetToolTip(wx.ToolTip("Select Temperature for Hotend")) root.htemp.Bind(wx.EVT_COMBOBOX, root.htemp_change) self.Add(root.htemp, pos=(2, 2), span=(1, 2)) root.settbtn = make_button(root.panel, _("Set"), root.do_settemp, _("Switch Hotend On"), size=(38, -1), style=wx.BU_EXACTFIT) root.printerControls.append(root.settbtn) self.Add(root.settbtn, pos=(2, 4), span=(1, 1)) self.Add(wx.StaticText(root.panel, -1, _("Bed:")), pos=(3, 0), span=(1, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) btemp_choices = [ root.bedtemps[i] + " (" + i + ")" for i in sorted(root.bedtemps.keys(), key=lambda x: root.temps[x]) ] root.setboff = make_button(root.panel, _("Off"), lambda e: root.do_bedtemp("off"), _("Switch Heated Bed Off"), size=(36, -1), style=wx.BU_EXACTFIT) root.printerControls.append(root.setboff) self.Add(root.setboff, pos=(3, 1), span=(1, 1)) if root.settings.last_bed_temperature not in map( float, root.bedtemps.values()): btemp_choices = [str(root.settings.last_bed_temperature) ] + btemp_choices root.btemp = wx.ComboBox(root.panel, -1, choices=btemp_choices, style=wx.CB_DROPDOWN, size=(80, -1)) root.btemp.SetToolTip(wx.ToolTip("Select Temperature for Heated Bed")) root.btemp.Bind(wx.EVT_COMBOBOX, root.btemp_change) self.Add(root.btemp, pos=(3, 2), span=(1, 2)) root.setbbtn = make_button(root.panel, _("Set"), root.do_bedtemp, ("Switch Heated Bed On"), size=(38, -1), style=wx.BU_EXACTFIT) root.printerControls.append(root.setbbtn) self.Add(root.setbbtn, pos=(3, 4), span=(1, 1)) root.btemp.SetValue(str(root.settings.last_bed_temperature)) root.htemp.SetValue(str(root.settings.last_temperature)) ## added for an error where only the bed would get (pla) or (abs). #This ensures, if last temp is a default pla or abs, it will be marked so. # if it is not, then a (user) remark is added. This denotes a manual entry for i in btemp_choices: if i.split()[0] == str(root.settings.last_bed_temperature).split( '.')[0] or i.split()[0] == str( root.settings.last_bed_temperature): root.btemp.SetValue(i) for i in htemp_choices: if i.split()[0] == str(root.settings.last_temperature).split( '.')[0] or i.split()[0] == str( root.settings.last_temperature): root.htemp.SetValue(i) if ('(' not in root.btemp.Value): root.btemp.SetValue(root.btemp.Value + ' (user)') if ('(' not in root.htemp.Value): root.htemp.SetValue(root.htemp.Value + ' (user)') root.tempdisp = wx.StaticText(root.panel, -1, "") root.edist = wx.SpinCtrl(root.panel, -1, "5", min=0, max=1000, size=(60, -1)) root.edist.SetBackgroundColour((225, 200, 200)) root.edist.SetForegroundColour("black") self.Add(root.edist, pos=(4, 2), span=(1, 2)) self.Add(wx.StaticText(root.panel, -1, _("mm")), pos=(4, 4), span=(1, 1)) root.edist.SetToolTip(wx.ToolTip("Amount to Extrude or Retract (mm)")) root.efeedc = wx.SpinCtrl(root.panel, -1, str(root.settings.e_feedrate), min=0, max=50000, size=(60, -1)) root.efeedc.SetToolTip(wx.ToolTip("Extrude / Retract speed (mm/min)")) root.efeedc.SetBackgroundColour((225, 200, 200)) root.efeedc.SetForegroundColour("black") root.efeedc.Bind(wx.EVT_SPINCTRL, root.setfeeds) self.Add(root.efeedc, pos=(5, 2), span=(1, 2)) self.Add(wx.StaticText(root.panel, -1, _("mm/\nmin")), pos=(5, 4), span=(1, 1)) root.xyfeedc.Bind(wx.EVT_SPINCTRL, root.setfeeds) root.zfeedc.Bind(wx.EVT_SPINCTRL, root.setfeeds) root.zfeedc.SetBackgroundColour((180, 255, 180)) root.zfeedc.SetForegroundColour("black") root.graph = Graph(root.panel, wx.ID_ANY) self.Add(root.graph, pos=(4, 5), span=(3, 1)) self.Add(root.tempdisp, pos=(7, 0), span=(1, 6))