Commit 2d3a356e authored by Guillaume Seguin's avatar Guillaume Seguin

Drop self.f (for memory optimization & code cleanup)

parent c630318b
...@@ -301,7 +301,6 @@ class pronsole(cmd.Cmd): ...@@ -301,7 +301,6 @@ class pronsole(cmd.Cmd):
self.recvlisteners = [] self.recvlisteners = []
self.in_macro = False self.in_macro = False
self.p.onlinecb = self.online self.p.onlinecb = self.online
self.f = None
self.fgcode = None self.fgcode = None
self.listing = 0 self.listing = 0
self.sdfiles = [] self.sdfiles = []
...@@ -736,10 +735,9 @@ class pronsole(cmd.Cmd): ...@@ -736,10 +735,9 @@ class pronsole(cmd.Cmd):
if not os.path.exists(filename): if not os.path.exists(filename):
self.log("File not found!") self.log("File not found!")
return return
self.f = [line.strip() for line in open(filename)] self.fgcode = gcoder.GCode(open(filename))
self.fgcode = gcoder.GCode(self.f)
self.filename = filename self.filename = filename
self.log("Loaded %s, %d lines." % (filename, len(self.f))) self.log("Loaded %s, %d lines." % (filename, len(self.fgcode)))
def complete_load(self, text, line, begidx, endidx): def complete_load(self, text, line, begidx, endidx):
s = line.split() s = line.split()
......
...@@ -205,7 +205,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -205,7 +205,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.capture_skip_newline = False self.capture_skip_newline = False
self.tempreport = "" self.tempreport = ""
self.monitor = 0 self.monitor = 0
self.f = None self.fgcode = None
self.skeinp = None self.skeinp = None
self.monitor_interval = 3 self.monitor_interval = 3
self.current_pos = [0, 0, 0] self.current_pos = [0, 0, 0]
...@@ -570,14 +570,12 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -570,14 +570,12 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.SetMenuBar(self.menustrip) self.SetMenuBar(self.menustrip)
def doneediting(self, gcode): def doneediting(self, gcode):
f = open(self.filename, "w") open(self.filename, "w").write("\n".join(gcode))
f.write("\n".join(gcode))
f.close()
wx.CallAfter(self.loadfile, None, self.filename) wx.CallAfter(self.loadfile, None, self.filename)
def do_editgcode(self, e = None): def do_editgcode(self, e = None):
if self.filename is not None: if self.filename is not None:
MacroEditor(self.filename, self.f, self.doneediting, 1) MacroEditor(self.filename, "\n".join([line.raw for line in self.fgcode]), self.doneediting, 1)
def new_macro(self, e = None): def new_macro(self, e = None):
dialog = wx.Dialog(self, -1, _("Enter macro name"), size = (260, 85)) dialog = wx.Dialog(self, -1, _("Enter macro name"), size = (260, 85))
...@@ -680,7 +678,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -680,7 +678,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
obj = e.GetEventObject() obj = e.GetEventObject()
popupmenu = wx.Menu() popupmenu = wx.Menu()
item = popupmenu.Append(-1, _("SD Upload")) item = popupmenu.Append(-1, _("SD Upload"))
if not self.f: if not self.fgcode:
item.Enable(False) item.Enable(False)
self.Bind(wx.EVT_MENU, self.upload, id = item.GetId()) self.Bind(wx.EVT_MENU, self.upload, id = item.GetId())
item = popupmenu.Append(-1, _("SD Print")) item = popupmenu.Append(-1, _("SD Print"))
...@@ -698,7 +696,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -698,7 +696,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
wx.CallAfter(self.btemp.SetInsertionPoint, 0) wx.CallAfter(self.btemp.SetInsertionPoint, 0)
def showwin(self, event): def showwin(self, event):
if self.f: if self.fgcode:
self.gwindow.Show(True) self.gwindow.Show(True)
self.gwindow.SetToolTip(wx.ToolTip("Mousewheel zooms the display\nShift / Mousewheel scrolls layers")) self.gwindow.SetToolTip(wx.ToolTip("Mousewheel zooms the display\nShift / Mousewheel scrolls layers"))
self.gwindow.Raise() self.gwindow.Raise()
...@@ -1341,12 +1339,11 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1341,12 +1339,11 @@ class PronterWindow(MainWindow, pronsole.pronsole):
fn = self.filename fn = self.filename
try: try:
self.filename = self.filename.replace(".stl", "_export.gcode").replace(".STL", "_export.gcode").replace(".obj", "_export.gcode").replace(".OBJ", "_export.gcode") self.filename = self.filename.replace(".stl", "_export.gcode").replace(".STL", "_export.gcode").replace(".obj", "_export.gcode").replace(".OBJ", "_export.gcode")
self.f = [line.strip() for line in open(self.filename)] self.fgcode = gcoder.GCode(open(self.filename))
self.fgcode = gcoder.GCode(self.f)
if self.p.online: if self.p.online:
wx.CallAfter(self.printbtn.Enable) wx.CallAfter(self.printbtn.Enable)
wx.CallAfter(self.status.SetStatusText, _("Loaded %s, %d lines") % (self.filename, len(self.f),)) wx.CallAfter(self.status.SetStatusText, _("Loaded %s, %d lines") % (self.filename, len(self.fgcode),))
wx.CallAfter(self.pausebtn.Disable) wx.CallAfter(self.pausebtn.Disable)
wx.CallAfter(self.printbtn.SetLabel, _("Print")) wx.CallAfter(self.printbtn.SetLabel, _("Print"))
...@@ -1407,9 +1404,8 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1407,9 +1404,8 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.skein(name) self.skein(name)
else: else:
self.filename = name self.filename = name
self.f = [line.strip() for line in open(self.filename)] self.fgcode = gcoder.GCode(open(self.filename))
self.fgcode = gcoder.GCode(self.f) self.status.SetStatusText(_("Loaded %s, %d lines") % (name, len(self.fgcode)))
self.status.SetStatusText(_("Loaded %s, %d lines") % (name, len(self.f)))
wx.CallAfter(self.printbtn.SetLabel, _("Print")) wx.CallAfter(self.printbtn.SetLabel, _("Print"))
wx.CallAfter(self.pausebtn.SetLabel, _("Pause")) wx.CallAfter(self.pausebtn.SetLabel, _("Pause"))
wx.CallAfter(self.pausebtn.Disable) wx.CallAfter(self.pausebtn.Disable)
...@@ -1446,7 +1442,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1446,7 +1442,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.p.send_now("M24") self.p.send_now("M24")
return return
if not self.f: if not self.fgcode:
wx.CallAfter(self.status.SetStatusText, _("No file loaded. Please use load first.")) wx.CallAfter(self.status.SetStatusText, _("No file loaded. Please use load first."))
return return
if not self.p.online: if not self.p.online:
...@@ -1477,7 +1473,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1477,7 +1473,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.recvlisteners.remove(self.uploadtrigger) self.recvlisteners.remove(self.uploadtrigger)
def upload(self, event): def upload(self, event):
if not self.f: if not self.fgcode:
return return
if not self.p.online: if not self.p.online:
return return
......
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