Britefury / django-labeller

An image labelling tool for creating segmentation data sets, for Django and Flask.
MIT License
134 stars 40 forks source link

Shortcut (keys) in flask #21

Open jaggzh opened 1 year ago

jaggzh commented 1 year ago

I'm trying to find if there are any already in here, but what do you think if some shortcuts were added? (When moving between images, some keys for the next action you want to take could save a lot of time). In my case, for example, I'm doing poly lines each image, (although I'd probably assign it to something on the left of the kb). (Sorry, I have no experience with flask so I'm a bit lost in this code).

jaggzh commented 1 year ago

Okay, I got 'g' hard coded for the poly line. I'm not sure if it's correct, but it's working.

        DjangoLabeller.prototype._overall_on_key_down = function (event) {
            if (this._mouse_within) {
                var handled = false;
                switch (event.keyCode) {
                    case 71: // g
                        var current = this.root_view.get_selected_entity();
                        if (current instanceof labelling_tool.PolygonalLabelEntity) {
                            this.set_current_tool(new labelling_tool.EditPolyTool(this.root_view, current));
                        } else {
                            this.set_current_tool(new labelling_tool.EditPolyTool(this.root_view, null));
                        }
                        handled = true;
                        break;
                    default:
                        console.log('_overall_on_key_down (other key hit: ' + event.keyCode + ')');
                        break;
                }
                if (!handled && this._current_tool !== null) {
                    handled = this._current_tool.on_key_down(event);
                }
                if (!handled) {
                    handled = this.on_key_down(event);
                }
                return handled;
            }
            else {
                return false;
            }
        };
jaggzh commented 1 year ago

Okay, for those who might find it useful, I modified the code for a couple keystrokes. Please feel free to use this repo/branch and even extend it to include other shortcuts: https://github.com/Britefury/django-labeller/pull/23