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