Skip to content

Commit

Permalink
Signal values can now be set directly by double-clicking on a signalT…
Browse files Browse the repository at this point in the history
…able entry (e.g. in List view) and typing a value into the text box that appears. Supports scalar and vector values with elements separated by commas.
  • Loading branch information
malloch committed Jun 8, 2022
1 parent 03ab85f commit 85f4f32
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
52 changes: 51 additions & 1 deletion js/SignalTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

// An object for the overall display
class SignalTable {
constructor(container, location, frame, graph) {
constructor(container, location, frame, graph, viewManager) {
this.graph = graph;
this.viewManager = viewManager;
this.location = location;
this.id = location + 'Table';
this.detail = true;
Expand Down Expand Up @@ -681,6 +682,55 @@ class SignalTable {
this.grow();

$(tds).off('click');
$(tds).on('dblclick', function(e) {
e.stopPropagation();
e.preventDefault();
_self.viewManager.escape();

let id = $(e.currentTarget)[0].id + '_edit';
$(e.currentTarget).append("<input id="+id+" style='margin-left:10px'>");
$("#"+$.escapeSelector(id)).on({
click: function(e) {
e.stopPropagation();
e.preventDefault();
_self.viewManager.escape();
},
keydown: function(e) {
e.stopPropagation();
// check enter or escape
switch (e.which) {
case 13:
let signame = e.currentTarget.id;
signame = signame.slice(0, signame.length-5);
let val = $(this).val();

// remove brackets if any
if (val[0] == '[')
val = val.slice(1)
if (val[val.length-1] == ']')
val = val.slice(0, val.length-1)

// split at commas
val = val.split(",");

let valid = true;
for (let i in val) {
val[i] = Number(val[i]);
if (isNaN(val[i]))
valid = false;
}

if (valid) {
// console.log("set_sig", {name: signame, value: val});
command.send("set_sig", {name: signame, value: val});
}
case 27:
$(this).remove();
break;
}
},
});
});
$(tds).on('click', function(e) {
if ($(e.currentTarget).hasClass('leaf')) {
// can't collapse leaves
Expand Down
10 changes: 8 additions & 2 deletions js/ViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ class ViewManager
};

_add_display_tables() {
this.tables.left = new SignalTable($('#container')[0], 'left', this.frame, this.graph);
this.tables.right = new SignalTable($('#container')[0], 'right', this.frame, this.graph);
this.tables.left = new SignalTable($('#container')[0], 'left', this.frame, this.graph, this);
this.tables.right = new SignalTable($('#container')[0], 'right', this.frame, this.graph, this);
}

_add_canvas() {
Expand Down Expand Up @@ -363,4 +363,10 @@ class ViewManager
}
});
}

escape() {
console.log("ViewManager.escape()");
let view = this.views[this.currentView];
view.escape();
}
}
2 changes: 1 addition & 1 deletion js/views/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ListView extends View {

pan(x, y, delta_x, delta_y) {
if (this.tablePan(x, y, delta_x, delta_y))
this.drawMaps();
this.drawMaps(0);
}

zoom(x, y, delta) {
Expand Down
30 changes: 27 additions & 3 deletions webmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ def on_map(type, map, event):

def find_sig(fullname):
names = fullname.split('/', 1)
dev = g.devices().filter(mpr.Property.NAME, names[0]).next()
dev = g.devices().filter(mpr.Property.NAME, names[0])
if dev:
sig = dev.signals().filter(mpr.Property.NAME, names[1]).next()
return sig
sig = dev.next().signals().filter(mpr.Property.NAME, names[1])
if not sig:
print('error: could not find signal', names[1])
return None
return sig.next()
else:
print('error: could not find device', names[0])
return None
Expand Down Expand Up @@ -232,6 +235,25 @@ def set_map_properties(props, map):
map[key] = val
map.push()

def set_sig_properties(props):
# check how arbitrary metadata are set – can we use this instead?
print('set_sig_properties()', props)

# find sig by name
sig = find_sig(props['name'])
if not sig:
return
print('found sig: ', sig)
del props['name']

# set metadata
for key in props:
if key == 'value':
print('trying to set remote signal value!')
sig.set_value(props[key])
else:
sig[key] = props[key]

def on_save(arg):
d = g.devices().filter(mpr.Property.NAME, arg['dev']).next()
fn = d.name+'.json'
Expand Down Expand Up @@ -353,6 +375,8 @@ def poll_and_push():
server.add_command_handler("add_signals",
lambda x: ("add_signals", [sig_props(s) for s in g.signals()]))

server.add_command_handler("set_sig", lambda x: set_sig_properties(x))

server.add_command_handler("add_maps",
lambda x: ("add_maps", [map_props(m) for m in g.maps()]))

Expand Down

0 comments on commit 85f4f32

Please sign in to comment.