Commit 8610d61a authored by Guillaume Seguin's avatar Guillaume Seguin

Factor out model to gcode rename and fix #394

This probably requires using an Unicode-based wx.
parent 559cf767
......@@ -22,6 +22,7 @@ import math, codecs
import shlex
from math import sqrt
import argparse
import locale
import printcore
from printrun.printrun_utils import install_locale
......@@ -795,7 +796,7 @@ class pronsole(cmd.Cmd):
if not filename:
self.log("No file name given.")
return
self.log("Loading file:" + filename)
self.log("Loading file: " + filename)
if not os.path.exists(filename):
self.log("File not found!")
return
......@@ -1418,7 +1419,8 @@ class pronsole(cmd.Cmd):
self.onecmd(command)
self.processing_args = False
if args.filename:
self.do_load(args.filename)
filename = args.filename.decode(locale.getpreferredencoding())
self.do_load(filename)
def parse_cmdline(self, args):
parser = argparse.ArgumentParser(description = 'Printrun 3D printer interface')
......
......@@ -1356,12 +1356,19 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.p.send_now("M21")
self.p.send_now("M20")
def model_to_gcode_filename(self, filename):
suffix = "_export.gcode"
for ext in [".stl", ".obj"]:
filename = filename.replace(ext, suffix)
filename = filename.replace(ext.upper(), suffix)
return filename
def skein_func(self):
try:
param = self.expandcommand(self.settings.slicecommand).encode()
param = self.expandcommand(self.settings.slicecommand)
print "Slicing: ", param
pararray = [i.replace("$s", self.filename).replace("$o", self.filename.replace(".stl", "_export.gcode").replace(".STL", "_export.gcode")).encode() for i in shlex.split(param.replace("\\", "\\\\").encode())]
#print pararray
output_filename = self.model_to_gcode_filename(self.filename)
pararray = [i.replace("$s", self.filename).replace("$o", output_filename) for i in shlex.split(param.replace("\\", "\\\\"))]
self.skeinp = subprocess.Popen(pararray, stderr = subprocess.STDOUT, stdout = subprocess.PIPE)
while True:
o = self.skeinp.stdout.read(1)
......@@ -1383,7 +1390,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
time.sleep(0.1)
fn = self.filename
try:
self.filename = self.filename.replace(".stl", "_export.gcode").replace(".STL", "_export.gcode").replace(".obj", "_export.gcode").replace(".OBJ", "_export.gcode")
self.filename = self.model_to_gcode_filename(self.filename)
self.fgcode = gcoder.GCode(open(self.filename))
if self.p.online:
wx.CallAfter(self.printbtn.Enable)
......
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