Commit b7ccfb20 authored by Guillaume Seguin's avatar Guillaume Seguin

Split gui source into multiple small units

parent 69a8e0cf
This diff is collapsed.
This diff is collapsed.
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import wx
from .utils import make_button
class LogPane(wx.BoxSizer):
def __init__(self, root, parentpanel = None):
super(LogPane, self).__init__(wx.VERTICAL)
if not parentpanel: parentpanel = root.panel
root.logbox = wx.TextCtrl(parentpanel, style = wx.TE_MULTILINE, size = (350, -1))
root.logbox.SetMinSize((100, -1))
root.logbox.SetEditable(0)
self.Add(root.logbox, 1, wx.EXPAND)
bottom_panel = root.newPanel(parentpanel)
lbrs = wx.BoxSizer(wx.HORIZONTAL)
root.commandbox = wx.TextCtrl(bottom_panel, style = wx.TE_PROCESS_ENTER)
root.commandbox.SetToolTip(wx.ToolTip(_("Send commands to printer\n(Type 'help' for simple\nhelp function)")))
root.commandbox.Bind(wx.EVT_TEXT_ENTER, root.sendline)
root.commandbox.Bind(wx.EVT_CHAR, root.cbkey)
root.commandbox.history = [u""]
root.commandbox.histindex = 1
#root.printerControls.append(root.commandbox)
lbrs.Add(root.commandbox, 1)
root.sendbtn = make_button(bottom_panel, _("Send"), root.sendline, _("Send Command to Printer"), style = wx.BU_EXACTFIT, container = lbrs)
#root.printerControls.append(root.sendbtn)
bottom_panel.SetSizer(lbrs)
self.Add(bottom_panel, 0, wx.EXPAND)
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import wx
from .utils import make_autosize_button
def MainToolbar(root, parentpanel = None, use_wrapsizer = False):
if not parentpanel: parentpanel = root.panel
if root.settings.lockbox:
root.locker = wx.CheckBox(parentpanel, label = _("Lock") + " ")
root.locker.Bind(wx.EVT_CHECKBOX, root.lock)
root.locker.SetToolTip(wx.ToolTip(_("Lock graphical interface")))
glob = wx.BoxSizer(wx.HORIZONTAL)
parentpanel = root.newPanel(parentpanel)
glob.Add(parentpanel, 1, flag = wx.EXPAND)
glob.Add(root.locker, 0, flag = wx.ALIGN_CENTER)
ToolbarSizer = wx.WrapSizer if use_wrapsizer and wx.VERSION > (2, 9) else wx.BoxSizer
self = ToolbarSizer(wx.HORIZONTAL)
root.rescanbtn = make_autosize_button(parentpanel, _("Port"), root.rescanports, _("Communication Settings\nClick to rescan ports"))
self.Add(root.rescanbtn, 0, wx.TOP | wx.LEFT, 0)
root.serialport = wx.ComboBox(parentpanel, -1, choices = root.scanserial(),
style = wx.CB_DROPDOWN)
root.serialport.SetToolTip(wx.ToolTip(_("Select Port Printer is connected to")))
root.rescanports()
self.Add(root.serialport)
self.Add(wx.StaticText(parentpanel, -1, "@"), 0, wx.RIGHT | wx.ALIGN_CENTER, 0)
root.baud = wx.ComboBox(parentpanel, -1,
choices = ["2400", "9600", "19200", "38400",
"57600", "115200", "250000"],
style = wx.CB_DROPDOWN, size = (100, -1))
root.baud.SetToolTip(wx.ToolTip(_("Select Baud rate for printer communication")))
try:
root.baud.SetValue("115200")
root.baud.SetValue(str(root.settings.baudrate))
except:
pass
self.Add(root.baud)
root.connectbtn = make_autosize_button(parentpanel, _("Connect"), root.connect, _("Connect to the printer"), self)
root.resetbtn = make_autosize_button(parentpanel, _("Reset"), root.reset, _("Reset the printer"), self)
self.AddStretchSpacer(prop = 1)
root.loadbtn = make_autosize_button(parentpanel, _("Load file"), root.loadfile, _("Load a 3D model file"), self)
root.sdbtn = make_autosize_button(parentpanel, _("SD"), root.sdmenu, _("SD Card Printing"), self)
root.printerControls.append(root.sdbtn)
root.printbtn = make_autosize_button(parentpanel, _("Print"), root.printfile, _("Start Printing Loaded File"), self)
root.printbtn.Disable()
root.pausebtn = make_autosize_button(parentpanel, _("Pause"), root.pause, _("Pause Current Print"), self)
root.offbtn = make_autosize_button(parentpanel, _("Off"), root.off, _("Turn printer off"), self)
root.printerControls.append(root.offbtn)
self.AddStretchSpacer(prop = 4)
if root.settings.lockbox:
parentpanel.SetSizer(self)
return glob
else:
return self
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import wx
def make_button(parent, label, callback, tooltip, container = None, size = wx.DefaultSize, style = 0):
button = wx.Button(parent, -1, label, style = style, size = size)
button.Bind(wx.EVT_BUTTON, callback)
button.SetToolTip(wx.ToolTip(tooltip))
if container:
container.Add(button)
return button
def make_autosize_button(*args):
return make_button(*args, size = (-1, -1), style = wx.BU_EXACTFIT)
def make_custom_button(root, parentpanel, i, style = 0):
btn = make_button(parentpanel, i.label, root.procbutton,
i.tooltip, style = style)
btn.SetBackgroundColour(i.background)
btn.SetForegroundColour("black")
btn.properties = i
root.btndict[i.command] = btn
root.printerControls.append(btn)
return btn
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import traceback
import wx
from printrun import gviz
class NoViz(object):
showall = False
def clear(self, *a):
pass
def addfile(self, *a, **kw):
pass
def addgcode(self, *a, **kw):
pass
def Refresh(self, *a):
pass
def setlayer(self, *a):
pass
class VizPane(wx.BoxSizer):
def __init__(self, root, parentpanel = None):
super(VizPane, self).__init__(wx.VERTICAL)
if not parentpanel: parentpanel = root.panel
if root.settings.mainviz == "None":
root.gviz = NoViz()
use2dview = root.settings.mainviz == "2D"
if root.settings.mainviz == "3D":
try:
import printrun.gcview
root.gviz = printrun.gcview.GcodeViewMainWrapper(parentpanel, root.build_dimensions_list, root = root, circular = root.settings.circular_bed)
root.gviz.clickcb = root.showwin
except:
use2dview = True
print "3D view mode requested, but we failed to initialize it."
print "Falling back to 2D view, and here is the backtrace:"
traceback.print_exc()
if use2dview:
root.gviz = gviz.Gviz(parentpanel, (300, 300),
build_dimensions = root.build_dimensions_list,
grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
extrusion_width = root.settings.preview_extrusion_width,
bgcolor = root.settings.bgcolor)
root.gviz.SetToolTip(wx.ToolTip(_("Click to examine / edit\n layers of loaded file")))
root.gviz.showall = 1
root.gviz.Bind(wx.EVT_LEFT_DOWN, root.showwin)
use3dview = root.settings.viz3d
if use3dview:
try:
import printrun.gcview
objects = None
if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper):
objects = root.gviz.objects
root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (600, 600), build_dimensions = root.build_dimensions_list, objects = objects, root = root, circular = root.settings.circular_bed)
except:
use3dview = False
print "3D view mode requested, but we failed to initialize it."
print "Falling back to 2D view, and here is the backtrace:"
traceback.print_exc()
if not use3dview:
root.gwindow = gviz.GvizWindow(build_dimensions = root.build_dimensions_list,
grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
extrusion_width = root.settings.preview_extrusion_width,
bgcolor = root.settings.bgcolor)
root.gwindow.Bind(wx.EVT_CLOSE, lambda x: root.gwindow.Hide())
if not isinstance(root.gviz, NoViz):
self.Add(root.gviz.widget, 1, flag = wx.SHAPED | wx.ALIGN_CENTER_HORIZONTAL)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment