Commit cc60367a authored by Guillaume Seguin's avatar Guillaume Seguin

New commandline paramters : -w/--web to request web interface

Also install webinterface deps and fix bug in configfile()
parent 64fca260
...@@ -20,15 +20,18 @@ def imagefile(filename): ...@@ -20,15 +20,18 @@ def imagefile(filename):
else: else:
return os.path.join(os.path.split(os.path.split(__file__)[0])[0], "images", filename) return os.path.join(os.path.split(os.path.split(__file__)[0])[0], "images", filename)
def pixmapfile(filename): def lookup_file(filename, prefixes):
for prefix in ['/usr/local/share/pixmaps', '/usr/share/pixmaps']: for prefix in prefixes:
candidate = os.path.join(prefix, filename) candidate = os.path.join(prefix, filename)
if os.path.exists(candidate): if os.path.exists(candidate):
return candidate return candidate
return filename return filename
def pixmapfile(filename):
return lookup_file(filename, ['/usr/local/share/pixmaps', '/usr/share/pixmaps'])
def sharedfile(filename):
return lookup_file(filename, ['/usr/local/share/pronterface', '/usr/share/pronterface'])
def configfile(filename): def configfile(filename):
candidate = os.path.expanduser("~/.printrun/%s" % filename) return lookup_file(filename, [os.path.expanduser("~/.printrun/"),])
if os.path.exists(candidate):
return candidate
return filename
...@@ -3,7 +3,7 @@ import pronterface ...@@ -3,7 +3,7 @@ import pronterface
import cherrypy, re, ConfigParser, threading, sys import cherrypy, re, ConfigParser, threading, sys
import os.path import os.path
from printrun.printrun_utils import configfile from printrun.printrun_utils import configfile, imagefile, sharedfile
users = {} users = {}
...@@ -363,13 +363,13 @@ def StartWebInterfaceThread(webInterface): ...@@ -363,13 +363,13 @@ def StartWebInterfaceThread(webInterface):
cherrypy.config.update({'engine.autoreload_on':False}) cherrypy.config.update({'engine.autoreload_on':False})
cherrypy.config.update(configfile("http.config")) cherrypy.config.update(configfile("http.config"))
conf = {'/css/style.css': {'tools.staticfile.on': True, conf = {'/css/style.css': {'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(current_dir, 'css/style.css'), 'tools.staticfile.filename': sharedfile('css/style.css'),
}, },
'/images/control_xy.png': {'tools.staticfile.on': True, '/images/control_xy.png': {'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(current_dir, 'images/control_xy.png'), 'tools.staticfile.filename': imagefile('control_xy.png'),
}, },
'/images/control_z.png': {'tools.staticfile.on': True, '/images/control_z.png': {'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(current_dir, 'images/control_z.png'), 'tools.staticfile.filename': imagefile('control_z.png'),
}} }}
cherrypy.config.update(configfile("http.config")) cherrypy.config.update(configfile("http.config"))
cherrypy.quickstart(webInterface, '/', config=conf) cherrypy.quickstart(webInterface, '/', config=conf)
......
...@@ -276,6 +276,7 @@ class pronsole(cmd.Cmd): ...@@ -276,6 +276,7 @@ class pronsole(cmd.Cmd):
self.helpdict["z_feedrate"] = _("Feedrate for Control Panel Moves in Z (default: 200mm/min)") self.helpdict["z_feedrate"] = _("Feedrate for Control Panel Moves in Z (default: 200mm/min)")
self.helpdict["final_command"] = _("Executable to run when the print is finished") self.helpdict["final_command"] = _("Executable to run when the print is finished")
self.commandprefixes='MGT$' self.commandprefixes='MGT$'
self.webrequested=False
def set_temp_preset(self,key,value): def set_temp_preset(self,key,value):
if not key.startswith("bed"): if not key.startswith("bed"):
...@@ -1210,11 +1211,13 @@ class pronsole(cmd.Cmd): ...@@ -1210,11 +1211,13 @@ class pronsole(cmd.Cmd):
def parse_cmdline(self,args): def parse_cmdline(self,args):
import getopt import getopt
opts,args = getopt.getopt(args, "c:e:h", ["conf=","config=","help"]) opts,args = getopt.getopt(args, "c:e:h:w", ["conf=","config=","help","web"])
for o,a in opts: for o,a in opts:
#print repr((o,a)) #print repr((o,a))
if o in ("-c","--conf","--config"): if o in ("-c","--conf","--config"):
self.load_rc(a) self.load_rc(a)
elif o in ("-w","--web"):
self.webrequested = True
elif o in ("-h","--help"): elif o in ("-h","--help"):
print "Usage: "+sys.argv[0]+' [-c filename [-c filename2 ... ] ] [-e "command" ...]' print "Usage: "+sys.argv[0]+' [-c filename [-c filename2 ... ] ] [-e "command" ...]'
print " -c | --conf | --config - override startup .pronsolerc file" print " -c | --conf | --config - override startup .pronsolerc file"
......
...@@ -53,16 +53,7 @@ from printrun.zbuttons import ZButtons ...@@ -53,16 +53,7 @@ from printrun.zbuttons import ZButtons
from printrun.graph import Graph from printrun.graph import Graph
from printrun.printrun_utils import pixmapfile, configfile from printrun.printrun_utils import pixmapfile, configfile
import pronsole import pronsole
webavail = False
try :
if webavail:
import cherrypy, printrun.webinterface
from threading import Thread
except:
print _("CherryPy is not installed. Web Interface Disabled.")
webavail = False
def dosify(name): def dosify(name):
return os.path.split(name)[1].split(".")[0][:8]+".g" return os.path.split(name)[1].split(".")[0][:8]+".g"
...@@ -171,10 +162,21 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -171,10 +162,21 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.cur_button=None self.cur_button=None
self.hsetpoint=0.0 self.hsetpoint=0.0
self.bsetpoint=0.0 self.bsetpoint=0.0
if webavail: self.webInterface=None
self.webInterface=webinterface.WebInterface(self) if self.webrequested:
self.webThread = Thread(target=webinterface.StartWebInterfaceThread, args=(self.webInterface, )) try :
self.webThread.start() import cherrypy
from printrun import webinterface
except:
print _("CherryPy is not installed. Web Interface Disabled.")
try:
self.webInterface=webinterface.WebInterface(self)
self.webThread=threading.Thread(target=webinterface.StartWebInterfaceThread, args=(self.webInterface, ))
self.webThread.start()
except:
print _("Failed to start web interface")
traceback.print_exc(file = sys.stdout)
self.webInterface = None
def startcb(self): def startcb(self):
self.starttime=time.time() self.starttime=time.time()
...@@ -326,7 +328,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -326,7 +328,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
print _("You cannot set negative temperatures. To turn the hotend off entirely, set its temperature to 0.") print _("You cannot set negative temperatures. To turn the hotend off entirely, set its temperature to 0.")
except Exception,x: except Exception,x:
print _("You must enter a temperature. (%s)" % (repr(x),)) print _("You must enter a temperature. (%s)" % (repr(x),))
if webavail: if self.webInterface:
self.webInterface.AddLog("You must enter a temperature. (%s)" % (repr(x),)) self.webInterface.AddLog("You must enter a temperature. (%s)" % (repr(x),))
def do_bedtemp(self,l=""): def do_bedtemp(self,l=""):
...@@ -344,15 +346,15 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -344,15 +346,15 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.setbedgui(f) self.setbedgui(f)
else: else:
print _("Printer is not online.") print _("Printer is not online.")
if webavail: if self.webInterface:
self.webInterface.AddLog("Printer is not online.") self.webInterface.AddLog("Printer is not online.")
else: else:
print _("You cannot set negative temperatures. To turn the bed off entirely, set its temperature to 0.") print _("You cannot set negative temperatures. To turn the bed off entirely, set its temperature to 0.")
if webavail: if self.webInterface:
self.webInterface.AddLog("You cannot set negative temperatures. To turn the bed off entirely, set its temperature to 0.") self.webInterface.AddLog("You cannot set negative temperatures. To turn the bed off entirely, set its temperature to 0.")
except: except:
print _("You must enter a temperature.") print _("You must enter a temperature.")
if webavail: if self.webInterface:
self.webInterface.AddLog("You must enter a temperature.") self.webInterface.AddLog("You must enter a temperature.")
def end_macro(self): def end_macro(self):
...@@ -373,7 +375,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -373,7 +375,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.delete_macro(macro_name) self.delete_macro(macro_name)
return return
print _("Cancelled.") print _("Cancelled.")
if webavail: if self.webInterface:
self.webInterface.AddLog("Cancelled.") self.webInterface.AddLog("Cancelled.")
return return
self.cur_macro_name = macro_name self.cur_macro_name = macro_name
...@@ -393,7 +395,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -393,7 +395,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.capture_skip_newline = True self.capture_skip_newline = True
return return
wx.CallAfter(self.logbox.AppendText,l) wx.CallAfter(self.logbox.AppendText,l)
if webavail: if self.webInterface:
self.webInterface.AppendLog(l) self.webInterface.AppendLog(l)
def scanserial(self): def scanserial(self):
...@@ -416,7 +418,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -416,7 +418,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
projectlayer.setframe(self,self.p).Show() projectlayer.setframe(self,self.p).Show()
else: else:
print _("Printer is not online.") print _("Printer is not online.")
if webavail: if self.webInterface:
self.webInterface.AddLog("Printer is not online.") self.webInterface.AddLog("Printer is not online.")
def popmenu(self): def popmenu(self):
...@@ -489,7 +491,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -489,7 +491,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
old_def = self.macros[macro] old_def = self.macros[macro]
elif len([c for c in macro.encode("ascii","replace") if not c.isalnum() and c != "_"]): elif len([c for c in macro.encode("ascii","replace") if not c.isalnum() and c != "_"]):
print _("Macro name may contain only ASCII alphanumeric symbols and underscores") print _("Macro name may contain only ASCII alphanumeric symbols and underscores")
if webavail: if self.webInterface:
self.webInterface.AddLog("Macro name may contain only alphanumeric symbols and underscores") self.webInterface.AddLog("Macro name may contain only alphanumeric symbols and underscores")
return return
elif hasattr(self.__class__,"do_"+macro): elif hasattr(self.__class__,"do_"+macro):
...@@ -972,7 +974,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -972,7 +974,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
def help_button(self): def help_button(self):
print _('Defines custom button. Usage: button <num> "title" [/c "colour"] command') print _('Defines custom button. Usage: button <num> "title" [/c "colour"] command')
if webavail: if self.webInterface:
self.webInterface.AddLog('Defines custom button. Usage: button <num> "title" [/c "colour"] command') self.webInterface.AddLog('Defines custom button. Usage: button <num> "title" [/c "colour"] command')
def do_button(self,argstr): def do_button(self,argstr):
...@@ -996,7 +998,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -996,7 +998,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
command=argstr.strip() command=argstr.strip()
if num<0 or num>=64: if num<0 or num>=64:
print _("Custom button number should be between 0 and 63") print _("Custom button number should be between 0 and 63")
if webavail: if self.webInterface:
self.webInterface.AddLog("Custom button number should be between 0 and 63") self.webInterface.AddLog("Custom button number should be between 0 and 63")
return return
while num >= len(self.custombuttons): while num >= len(self.custombuttons):
...@@ -1264,7 +1266,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1264,7 +1266,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.cur_button=None self.cur_button=None
except: except:
print _("event object missing") print _("event object missing")
if webavail: if self.webInterface:
self.webInterface.AddLog("event object missing") self.webInterface.AddLog("event object missing")
self.cur_button=None self.cur_button=None
raise raise
...@@ -1282,7 +1284,8 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1282,7 +1284,8 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
except: except:
pass pass
self.Destroy() self.Destroy()
if webavail: if self.webInterface:
from printrun import webinterface
webinterface.KillWebInterfaceThread() webinterface.KillWebInterfaceThread()
def do_monitor(self,l=""): def do_monitor(self,l=""):
...@@ -1296,16 +1299,16 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1296,16 +1299,16 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
wx.CallAfter(self.monitorbox.SetValue,self.monitor_interval>0) wx.CallAfter(self.monitorbox.SetValue,self.monitor_interval>0)
except: except:
print _("Invalid period given.") print _("Invalid period given.")
if webavail: if self.webInterface:
self.webInterface.AddLog("Invalid period given.") self.webInterface.AddLog("Invalid period given.")
self.setmonitor(None) self.setmonitor(None)
if self.monitor: if self.monitor:
print _("Monitoring printer.") print _("Monitoring printer.")
if webavail: if self.webInterface:
self.webInterface.AddLog("Monitoring printer.") self.webInterface.AddLog("Monitoring printer.")
else: else:
print _("Done monitoring.") print _("Done monitoring.")
if webavail: if self.webInterface:
self.webInterface.AddLog("Done monitoring.") self.webInterface.AddLog("Done monitoring.")
...@@ -1323,7 +1326,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1323,7 +1326,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
if not len(command): if not len(command):
return return
wx.CallAfter(self.logbox.AppendText,">>>"+command+"\n") wx.CallAfter(self.logbox.AppendText,">>>"+command+"\n")
if webavail: if self.webInterface:
self.webInterface.AppendLog(">>>"+command+"\n") self.webInterface.AppendLog(">>>"+command+"\n")
self.onecmd(str(command)) self.onecmd(str(command))
self.commandbox.SetSelection(0,len(command)) self.commandbox.SetSelection(0,len(command))
...@@ -1487,7 +1490,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1487,7 +1490,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
import shlex import shlex
param = self.expandcommand(self.settings.slicecommand).encode() param = self.expandcommand(self.settings.slicecommand).encode()
print "Slicing: ",param print "Slicing: ",param
if webavail: if self.webInterface:
self.webInterface.AddLog("Slicing: "+param) self.webInterface.AddLog("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())] 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 #print pararray
...@@ -1500,7 +1503,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1500,7 +1503,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.stopsf=1 self.stopsf=1
except: except:
print _("Failed to execute slicing software: ") print _("Failed to execute slicing software: ")
if webavail: if self.webInterface:
self.webInterface.AddLog("Failed to execute slicing software: ") self.webInterface.AddLog("Failed to execute slicing software: ")
self.stopsf=1 self.stopsf=1
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
...@@ -1587,7 +1590,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -1587,7 +1590,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
Xtot,Ytot,Ztot,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax = pronsole.measurements(self.f) Xtot,Ytot,Ztot,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax = pronsole.measurements(self.f)
print pronsole.totalelength(self.f), _("mm of filament used in this print\n") print pronsole.totalelength(self.f), _("mm of filament used in this print\n")
print _("the print goes from %f mm to %f mm in X\nand is %f mm wide\n") % (Xmin, Xmax, Xtot) print _("the print goes from %f mm to %f mm in X\nand is %f mm wide\n") % (Xmin, Xmax, Xtot)
if webavail: if self.webInterface:
self.webInterface.AddLog(_("the print goes from %f mm to %f mm in X\nand is %f mm wide\n") % (Xmin, Xmax, Xtot)) self.webInterface.AddLog(_("the print goes from %f mm to %f mm in X\nand is %f mm wide\n") % (Xmin, Xmax, Xtot))
print _("the print goes from %f mm to %f mm in Y\nand is %f mm wide\n") % (Ymin, Ymax, Ytot) print _("the print goes from %f mm to %f mm in Y\nand is %f mm wide\n") % (Ymin, Ymax, Ytot)
print _("the print goes from %f mm to %f mm in Z\nand is %f mm high\n") % (Zmin, Zmax, Ztot) print _("the print goes from %f mm to %f mm in Z\nand is %f mm high\n") % (Zmin, Zmax, Ztot)
...@@ -1855,7 +1858,7 @@ class macroed(wx.Dialog): ...@@ -1855,7 +1858,7 @@ class macroed(wx.Dialog):
self.callback(self.e.GetValue().split("\n")) self.callback(self.e.GetValue().split("\n"))
def close(self,ev): def close(self,ev):
self.Destroy() self.Destroy()
if webavail: if self.webInterface:
webinterface.KillWebInterfaceThread() webinterface.KillWebInterfaceThread()
def unindent(self,text): def unindent(self,text):
self.indent_chars = text[:len(text)-len(text.lstrip())] self.indent_chars = text[:len(text)-len(text.lstrip())]
......
...@@ -130,6 +130,13 @@ for basedir, subdirs, files in os.walk("locale"): ...@@ -130,6 +130,13 @@ for basedir, subdirs, files in os.walk("locale"):
files = map(lambda x: os.path.join(basedir, x), files) files = map(lambda x: os.path.join(basedir, x), files)
data_files.append ((destpath, files)) data_files.append ((destpath, files))
extra_data_dirs = ["css"]
for extra_data_dir in extra_data_dirs:
for basedir, subdirs, files in os.walk(extra_data_dir):
files = map(lambda x: os.path.join(basedir, x), files)
destpath = os.path.join("share", "pronterface", basedir)
data_files.append ((destpath, files))
setup ( setup (
name = "Printrun", name = "Printrun",
description = "Host software for 3D printers", description = "Host software for 3D printers",
......
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