Made it far less likely for the UI to lock up

This commit is contained in:
David Carley
2021-03-23 21:19:45 -07:00
parent 47cec0dae3
commit a46230656e
13 changed files with 62 additions and 46 deletions

View File

@@ -493,18 +493,19 @@ module.exports = {
const toolpath = await api.get(`path/${file}`);
this.toolpath_progress = toolpath.progress;
if (typeof toolpath.progress == 'undefined') {
if (toolpath.progress === 1 || typeof toolpath.progress == 'undefined') {
this.showGcodeMessage = false
if (toolpath.bounds) {
toolpath.filename = file;
this.toolpath_progress = 1;
this.toolpath = toolpath;
const state = this.$root.state;
const bounds = toolpath.bounds;
for (let axis of 'xyzabc') {
Vue.set(state, 'path_min_' + axis, bounds.min[axis]);
Vue.set(state, 'path_max_' + axis, bounds.max[axis]);
Vue.set(state, 'path_min_' + axis, toolpath.bounds.min[axis]);
Vue.set(state, 'path_max_' + axis, toolpath.bounds.max[axis]);
}
}
}
}
@@ -540,29 +541,47 @@ module.exports = {
},
upload: function (e) {
var files = e.target.files || e.dataTransfer.files;
if (!files.length) return;
upload: async function (e) {
const files = e.target.files || e.dataTransfer.files;
if (!files.length) {
return;
}
var file = files[0];
var fd = new FormData();
const file = files[0];
const extension = file.name.split(".").pop();
switch (extension.toLowerCase()) {
case "nc":
case "ngc":
case "gcode":
case "gc":
break;
default:
alert(`Unsupported file type: ${extension}`);
return;
}
const fd = new FormData();
fd.append('gcode', file);
api.upload('file', fd)
.done(function () {
try {
await api.upload('file', fd);
this.last_file_time = undefined; // Force reload
this.$broadcast('gcode-reload', file.name);
}.bind(this)).fail(function (error) {
api.alert('Upload failed', error)
}.bind(this));
} catch (err) {
api.alert('Upload failed', err)
}
},
delete_current: function () {
if (this.state.selected)
if (this.state.selected) {
api.delete('file/' + this.state.selected);
}
this.deleteGCode = false;
},

View File

@@ -36,14 +36,8 @@ script#console-template(type="text/x-template")
table
tr
th Level
th Source
th Location
th Repeat
th Message
tr(v-for="msg in messages", class="log-{{msg.level || 'info'}}")
td {{msg.level || 'info'}}
td {{msg.source || ''}}
td {{msg.where || ''}}
td {{msg.repeat}}
td.message {{msg.msg}}

View File

@@ -413,7 +413,7 @@ script#control-view-template(type="text/x-template")
form.gcode-file-input.file-upload
input(type="file", @change="upload", :disabled="!is_ready",
accept="text/*,.nc,.gcode,.gc,.ngc,.txt,.tap,.cnc")
accept=".nc,.ngc,.gcode,.gc")
a(:disabled="!state.selected", download,
:href="'/api/file/' + state.selected",

View File

@@ -128,7 +128,7 @@ class AVREmu(object):
except Exception:
self.close()
self.log.exception('Failed to start bbemu')
self.log.exception('Internal error: Failed to start bbemu')
def set_handlers(self, read_cb, write_cb):

View File

@@ -429,7 +429,7 @@ class Camera(object):
self._close_dev()
self.log.info('Closed camera')
except: self.log.exception('Exception while closing camera')
except: self.log.exception('Internal error: Exception while closing camera')
finally: self.dev = None

View File

@@ -72,7 +72,7 @@ class CommandQueue():
try:
if cb is not None: cb(*args, **kwargs)
except Exception:
self.log.exception('During command queue callback')
self.log.exception('Internal error: Command queue callback error')

View File

@@ -52,7 +52,7 @@ class Config(object):
encoding = 'utf-8') as f:
self.template = json.load(f)
except Exception: self.log.exception()
except Exception: self.log.exception('Internal error: Failed to load config template')
def get(self, name, default = None):
@@ -73,7 +73,7 @@ class Config(object):
try:
self.upgrade(config)
except Exception: self.log.exception()
except Exception: self.log.exception('Internal error: Failed to upgrade config')
except Exception as e:
self.log.warning('%s', e)

View File

@@ -67,7 +67,7 @@ class Ctrl(object):
os.environ['GCODE_SCRIPT_PATH'] = self.get_upload()
except Exception: self.log.get('Ctrl').exception()
except Exception: self.log.get('Ctrl').exception('Internal error: Control initialization failed')
def __del__(self): print('Ctrl deleted')

View File

@@ -79,7 +79,11 @@ class FileHandler(bbctrl.APIHandler):
if not filename: raise HTTPError(400, 'Missing filename')
filename = os.path.basename(filename)
try:
with open(self.get_upload(filename).encode('utf8'), 'r') as f:
self.write(f.read())
except Exception:
self.get_ctrl().state.select_file('')
raise HTTPError(400, "Unable to read file - doesn't appear to be GCode.")
self.get_ctrl().state.select_file(filename)

View File

@@ -101,8 +101,8 @@ class Logger(object):
def exception(self, *args, **kwargs):
msg = traceback.format_exc()
if len(args): msg = args[0] % args[1:] + '\n' + msg
self._log(ERROR, msg, **kwargs)
self._log(INFO, msg, **kwargs)
self._log(ERROR, *args, **kwargs)
class Log(object):
def __init__(self, args, ioloop, path):

View File

@@ -99,6 +99,6 @@ class MonitorTemp(object):
self.update_camera(temp)
self.log_warnings(temp)
except: self.log.exception()
except: self.log.exception('Internal error: Temperature status')
self.ioloop.call_later(5, self.callback)

View File

@@ -357,7 +357,7 @@ class Planner():
self.cmdq.clear()
except:
self.log.exception()
self.log.exception('Internal error: Planner stop')
self.reset()
@@ -374,7 +374,7 @@ class Planner():
self.planner.restart(id, position)
except:
self.log.exception()
self.log.exception('Internal error: Planner restart')
self.stop()
@@ -391,5 +391,5 @@ class Planner():
self.stop()
except:
self.log.exception()
self.log.exception('Internal error: Planner next')
self.stop()

View File

@@ -134,7 +134,7 @@ class Plan(object):
return meta, positions, speeds
except:
self.preplanner.log.exception()
self.preplanner.log.exception('Internal error: Preplanner read')
# Clean
for path in self.files:
@@ -203,8 +203,7 @@ class Plan(object):
self.future.set_result(self._read())
except:
self.preplanner.log.exception()
self.preplanner.log.exception("Failed to load file - doesn't appear to be GCode.")
class Preplanner(object):