Refactor and confirm exits while printing.

Presently, one might accidentally terminate a print with a CTR-D while
printing. Now we ask the user to confirm exiting if there is a print
going when they try to exit.
master
Christopher Olah 2013-02-02 21:24:07 -05:00
parent 786baebbf8
commit c20b270b84
1 changed files with 19 additions and 11 deletions

View File

@ -131,6 +131,14 @@ def estimate_duration(g):
#print "Total Duration: " #, time.strftime('%H:%M:%S', time.gmtime(totalduration)) #print "Total Duration: " #, time.strftime('%H:%M:%S', time.gmtime(totalduration))
return "{0:d} layers, ".format(int(layercount)) + str(datetime.timedelta(seconds = int(totalduration))) return "{0:d} layers, ".format(int(layercount)) + str(datetime.timedelta(seconds = int(totalduration)))
def confirm():
y_or_n = raw_input("y/n: ")
if y_or_n == "y":
return True
elif y_or_n != "n":
return confirm()
return False
class Settings: class Settings:
#def _temperature_alias(self): return {"pla":210, "abs":230, "off":0} #def _temperature_alias(self): return {"pla":210, "abs":230, "off":0}
#def _temperature_validate(self, v): #def _temperature_validate(self, v):
@ -957,14 +965,7 @@ class pronsole(cmd.Cmd):
f = float(l) f = float(l)
if f>=0: if f>=0:
if f > 250: if f > 250:
def confirm(): print f, " is a high temperature to set your extruder to. Are you sure you want to do that?"
print f, " is a high temperature to set your extruder to. Are you sure you want to do that?"
y_or_n = raw_input("y/n: ")
if y_or_n == "y":
return True
elif y_or_n != "n":
return confirm()
return False
if not confirm(): if not confirm():
return return
if self.p.online: if self.p.online:
@ -1144,8 +1145,14 @@ class pronsole(cmd.Cmd):
def do_exit(self, l): def do_exit(self, l):
print "Disconnecting from printer..." print "Disconnecting from printer..."
self.p.disconnect() print self.p.printing
if self.p.printing:
print "Are you sure you want to exit while printing?"
print "(this will terminate the print)."
if not confirm():
return False
print "Exiting program. Goodbye!" print "Exiting program. Goodbye!"
self.p.disconnect()
return True return True
def help_exit(self): def help_exit(self):
@ -1335,8 +1342,9 @@ class pronsole(cmd.Cmd):
line = raw_input(self.prompt) line = raw_input(self.prompt)
except EOFError: except EOFError:
print "" print ""
self.do_exit("") should_exit = self.do_exit("")
exit() if should_exit:
exit()
except KeyboardInterrupt: except KeyboardInterrupt:
print "" print ""
line = "" line = ""