Key event method

         * Forces grid update on <Enter> key
         * Handles insertion of cell access code
188734
def OnChar(self, event):
        

        if not self.ignore_changes:

            # Handle special keys
            keycode = event.GetKeyCode()

            if keycode == 13 and not self.GetStringSelection():
                # <Enter> pressed and no selection --> Focus on grid
                self.main_window.grid.SetFocus()

                # Ignore <Ctrl> + <Enter> and Quote content
                if event.ControlDown():
                    self.SetValue(quote(self.GetValue()))

                # Do not process <Enter>
                return

            elif keycode == 13 and self.GetStringSelection():
                # <Enter> pressed and selection
                # --> Place cursor at end of selection and clear selection
                selection_start, selection_stop = self.Selection
                self.SetSelection(selection_stop, selection_stop)

                # Do not process <Enter>
                return

            elif keycode == 9 and jedi is None:
                # Ignore the <Tab>
                return

            elif keycode == 9 and jedi is not None:
                #  If auto completion library jedi is present
                # <Tab> pressed --> show docstring tooltip

                tiptext = ""

                code = "".join(self.GetValue().split("\n"))
                position = self.GetInsertionPoint()

                # Get the docstring
                code_array = self.parent.parent.parent.grid.code_array
                env = code_array.get_globals()
                try:
                    script = jedi.Interpreter(code, [env], line=1,
                                              column=position)
                except ValueError:
                    # Jedi has thrown an error
                    event.Skip()
                    return

                completions = script.completions()
                completes = [completion.complete for completion in completions]
                complete = common_start(completes)

                if complete and \
                   not self.GetSelection()[1] > self.GetSelection()[0]:
                    # There is a non-empty completion
                    insertion_point = self.GetInsertionPoint()
                    self.write(complete)
                    if len(completes) > 1:
                        self.SetSelection(insertion_point,
                                          insertion_point + len(complete))

                words = [completion.name for completion in completions]

                docs = []
                for completion in completions:
                    doc = completion.docstring(fast=False)
                    if not doc and code:
                        # Is the completion part of a module?
                        code_segment = \
                            code[:position+1].split()[-1]
                        module_name = code_segment.rsplit(".", 1)[0]
                        try:
                            module = env[module_name]
                            doc = getattr(module, completion.name).__doc__
                        except (KeyError, AttributeError):
                            pass

                    if not doc:
                        name = completion.name
                        try:
                            # Is the completion a builtin?
                            doc = getattr(__builtin__, name).__doc__
                        except AttributeError:
                            pass
                    docs.append(doc)

                try:
                    dws = [": ".join([w, d]) for w, d in zip(words, docs)]

                    tiptext = "\n \n".join(dws)
                except TypeError:
                    pass

                # Cut tiptext length because Tooltip fails for long strings

                self.SetToolTip(wx.ToolTip(tiptext[:MAX_TOOLTIP_LENGTH]))

                # Do not process <Tab>
                return

        event.Skip()
1108804
def paste(self, key, data):
        

        data_gen = self._get_paste_data_gen(key, data)

        self.grid.actions.paste(key[:2], data_gen, freq=1000)

        self.main_window.grid.ForceRefresh()
1247459
private void onKeyUpdated(final int index, final Map.Entry<String, String> object, final String value) {
        final HashMap<String, String> _m = new LinkedHashMap<String, String>(getValue());
        final String lastKeyValue = object.getKey();
        String mapValue = "";
        if (lastKeyValue != null) {
            mapValue = _m.remove(lastKeyValue);
        }
        _m.put(value, mapValue);
        setValue(_m, true);
    }
157719
function (charCode, keyCode) {
                var dataModel = this._dataModel;
                var report;
                if (domEvent.isNavigationKey(keyCode)) {
                    var newIdx;
                    var validationKey = false;
                    if (keyCode == domEvent.KC_LEFT || keyCode == domEvent.KC_UP) {
                        newIdx = dataModel.selectedIdx - 1;
                    } else if (keyCode == domEvent.KC_RIGHT || keyCode == domEvent.KC_DOWN) {
                        newIdx = dataModel.selectedIdx + 1;
                    } else if (keyCode == domEvent.KC_PAGE_UP) {
                        newIdx = dataModel.selectedIdx - (dataModel.pageSize - 1);
                    } else if (keyCode == domEvent.KC_PAGE_DOWN) {
                        newIdx = dataModel.selectedIdx + (dataModel.pageSize - 1);
                    } else if (keyCode == domEvent.KC_HOME) {
                        newIdx = 0;
                    } else if (keyCode == domEvent.KC_END) {
                        newIdx = dataModel.listContent.length - 1;
                    } else if (keyCode == domEvent.KC_ENTER) {
                        // when pressing enter, the currently highlighted item in the dropdown becomes the current
                        // value:
                        newIdx = dataModel.selectedIdx;
                        validationKey = true;
                    } else if (keyCode == domEvent.KC_ESCAPE) {
                        // pressing escape has no effect if the popup is not open
                        // it only closes the popup when it is open (does not update the data model)
                        if (this._listWidget) {
                            report = this._createReport(false);
                            report.displayDropDown = false;
                            report.cancelKeyStroke = true;
                            jsonUtils.setValue(dataModel, 'selectedIdx', dataModel.displayIdx);
                        }
                    } else if (keyCode == domEvent.KC_TAB) {
                        // when pressing tab, the currently selected item stays the current value:
                        newIdx = dataModel.displayIdx;
                        validationKey = true;
                    }
                    if (newIdx != null) {
                        this._setLastTypedKeys(null);
                        this._setDisplayIdx(newIdx);
                        report = this._createReport(validationKey);
                        // never cancel TAB keystroke, and ENTER should not be canceled when the list widget is no
                        // longer displayed
                        report.cancelKeyStroke = (keyCode != domEvent.KC_TAB && (keyCode != domEvent.KC_ENTER || this._listWidget != null));
                        if (this._listWidget && validationKey) {
                            report.displayDropDown = false;
                        }
                    }
                } else {
                    var lastTypedKeys = dataModel.lastTypedKeys;
                    var newMatch = (lastTypedKeys == null);
                    if (newMatch) {
                        lastTypedKeys = "";
                    }
                    var newLastTypedKeys;
                    if (keyCode == domEvent.KC_BACKSPACE) {
                        newLastTypedKeys = this._getTypedValueOnDelete(keyCode, lastTypedKeys, lastTypedKeys.length, lastTypedKeys.length).nextValue;
                        // we do not look for a new match when pressing backspace, only save the resulting lastTypedKeys
                    } else {
                        newLastTypedKeys = this._getTypedValue(charCode, lastTypedKeys, lastTypedKeys.length, lastTypedKeys.length).nextValue;
                        newLastTypedKeys = newLastTypedKeys.toLowerCase();
                        var matchingIndex = this._findMatch(newLastTypedKeys, newMatch);
                        if (matchingIndex == -1) {
                            matchingIndex = this._findLetterMatch(newLastTypedKeys);
                        }
                        if (matchingIndex > -1) {
                            this._setDisplayIdx(matchingIndex);
                        }
                    }
                    report = this._createReport(false);
                    report.cancelKeyStroke = true;
                    this._setLastTypedKeys(newLastTypedKeys);
                }
                return report;
            }
664527
function(e) {
    var nKey = Ev.getCharCode(e);
    var bSHIFT = e.shiftKey;
    if((nKey == 9) || !bSHIFT) {
        this._handleSingleCellSelectionByKey(e);
        return;
    }

    if((nKey > 36) && (nKey < 41)) {
        // Validate trigger
        var oTrigger = this._getSelectionTrigger();
        // Arrow selection only works if last selected row is on current page
        if(!oTrigger) {
            return null;
        }

        Ev.stopEvent(e);

        // Validate anchor
        var oAnchor = this._getSelectionAnchor(oTrigger);

        var i, elNewRow, elNew;
        var allRows = this.getTbodyEl().rows;
        var elThisRow = oTrigger.el.parentNode;

        // Arrow down
        if(nKey == 40) {
            elNewRow = this.getNextTrEl(oTrigger.el);

            // Selecting away from anchor cell
            if(oAnchor.recordIndex <= oTrigger.recordIndex) {
                // Select all cells to the end of this row
                for(i=oTrigger.colKeyIndex+1; i<elThisRow.cells.length; i++){
                    elNew = elThisRow.cells[i];
                    this.selectCell(elNew);
                }

                // Select some of the cells on the next row down
                if(elNewRow) {
                    for(i=0; i<=oTrigger.colKeyIndex; i++){
                        elNew = elNewRow.cells[i];
                        this.selectCell(elNew);
                    }
                }
            }
            // Unselecting towards anchor cell
            else {
                // Unselect all cells to the end of this row
                for(i=oTrigger.colKeyIndex; i<elThisRow.cells.length; i++){
                    this.unselectCell(elThisRow.cells[i]);
                }

                // Unselect some of the cells on the next row down
                if(elNewRow) {
                    for(i=0; i<oTrigger.colKeyIndex; i++){
                        this.unselectCell(elNewRow.cells[i]);
                    }
                }
            }
        }
        // Arrow up
        else if(nKey == 38) {
            elNewRow = this.getPreviousTrEl(oTrigger.el);

            // Selecting away from anchor cell
            if(oAnchor.recordIndex >= oTrigger.recordIndex) {
                // Select all the cells to the beginning of this row
                for(i=oTrigger.colKeyIndex-1; i>-1; i--){
                    elNew = elThisRow.cells[i];
                    this.selectCell(elNew);
                }

                // Select some of the cells from the end of the previous row
                if(elNewRow) {
                    for(i=elThisRow.cells.length-1; i>=oTrigger.colKeyIndex; i--){
                        elNew = elNewRow.cells[i];
                        this.selectCell(elNew);
                    }
                }
            }
            // Unselecting towards anchor cell
            else {
                // Unselect all the cells to the beginning of this row
                for(i=oTrigger.colKeyIndex; i>-1; i--){
                    this.unselectCell(elThisRow.cells[i]);
                }

                // Unselect some of the cells from the end of the previous row
                if(elNewRow) {
                    for(i=elThisRow.cells.length-1; i>oTrigger.colKeyIndex; i--){
                        this.unselectCell(elNewRow.cells[i]);
                    }
                }
            }
        }
        // Arrow right
        else if(nKey == 39) {
            elNewRow = this.getNextTrEl(oTrigger.el);

            // Selecting away from anchor cell
            if(oAnchor.recordIndex < oTrigger.recordIndex) {
                // Select the next cell to the right
                if(oTrigger.colKeyIndex < elThisRow.cells.length-1) {
                    elNew = elThisRow.cells[oTrigger.colKeyIndex+1];
                    this.selectCell(elNew);
                }
                // Select the first cell of the next row
                else if(elNewRow) {
                    elNew = elNewRow.cells[0];
                    this.selectCell(elNew);
                }
            }
            // Unselecting towards anchor cell
            else if(oAnchor.recordIndex > oTrigger.recordIndex) {
                this.unselectCell(elThisRow.cells[oTrigger.colKeyIndex]);

                // Unselect this cell towards the right
                if(oTrigger.colKeyIndex < elThisRow.cells.length-1) {
                }
                // Unselect this cells towards the first cell of the next row
                else {
                }
            }
            // Anchor is on this row
            else {
                // Selecting away from anchor
                if(oAnchor.colKeyIndex <= oTrigger.colKeyIndex) {
                    // Select the next cell to the right
                    if(oTrigger.colKeyIndex < elThisRow.cells.length-1) {
                        elNew = elThisRow.cells[oTrigger.colKeyIndex+1];
                        this.selectCell(elNew);
                    }
                    // Select the first cell on the next row
                    else if(oTrigger.trIndex < allRows.length-1){
                        elNew = elNewRow.cells[0];
                        this.selectCell(elNew);
                    }
                }
                // Unselecting towards anchor
                else {
                    // Unselect this cell towards the right
                    this.unselectCell(elThisRow.cells[oTrigger.colKeyIndex]);
                }
            }
        }
        // Arrow left
        else if(nKey == 37) {
            elNewRow = this.getPreviousTrEl(oTrigger.el);

            // Unselecting towards the anchor
            if(oAnchor.recordIndex < oTrigger.recordIndex) {
                this.unselectCell(elThisRow.cells[oTrigger.colKeyIndex]);

                // Unselect this cell towards the left
                if(oTrigger.colKeyIndex > 0) {
                }
                // Unselect this cell towards the last cell of the previous row
                else {
                }
            }
            // Selecting towards the anchor
            else if(oAnchor.recordIndex > oTrigger.recordIndex) {
                // Select the next cell to the left
                if(oTrigger.colKeyIndex > 0) {
                    elNew = elThisRow.cells[oTrigger.colKeyIndex-1];
                    this.selectCell(elNew);
                }
                // Select the last cell of the previous row
                else if(oTrigger.trIndex > 0){
                    elNew = elNewRow.cells[elNewRow.cells.length-1];
                    this.selectCell(elNew);
                }
            }
            // Anchor is on this row
            else {
                // Selecting away from anchor cell
                if(oAnchor.colKeyIndex >= oTrigger.colKeyIndex) {
                    // Select the next cell to the left
                    if(oTrigger.colKeyIndex > 0) {
                        elNew = elThisRow.cells[oTrigger.colKeyIndex-1];
                        this.selectCell(elNew);
                    }
                    // Select the last cell of the previous row
                    else if(oTrigger.trIndex > 0){
                        elNew = elNewRow.cells[elNewRow.cells.length-1];
                        this.selectCell(elNew);
                    }
                }
                // Unselecting towards anchor cell
                else {
                    this.unselectCell(elThisRow.cells[oTrigger.colKeyIndex]);

                    // Unselect this cell towards the left
                    if(oTrigger.colKeyIndex > 0) {
                    }
                    // Unselect this cell towards the last cell of the previous row
                    else {
                    }
                }
            }
        }
    }
}
441131
def OnButtonCell(self, event):
        """"""

        # The button text
        text = event.text

        with undo.group(_("Button")):
            self.grid.actions.set_attr("button_cell", text)

        self.grid.ForceRefresh()

        self.grid.update_attribute_toolbar()

        event.Skip()
105315
public void appendUpdateEvent(final Object rowKey, final int colIndex, final Object rowData, final Object oldValue,
                final Object newValue) {
        updates.add(new SheetUpdate(rowKey, colIndex, rowData, oldValue, newValue));
    }
581633
function setCell(map, key, columnCount, columnIndex, value) {
  if (!map.has(key)) map.set(key, new Array(columnCount));
  map.get(key)[columnIndex] = value;
}
467771
function(event) {
		var datalistSelect = event.currentTarget,
			datalist = datalistSelect.parentNode,
			input = dcmnt.querySelector('input[list="' + datalist.id + '"]');

		// Check for whether the events target was a select or whether the input doesn't exist
		if (datalistSelect.tagName.toLowerCase() !== 'select' || input === null) {
			return;
		}

		var eventType = event.type,
			// ENTER and ESC
			visible =
				eventType === 'keydown' &&
				(event.keyCode !== keyENTER && event.keyCode !== keyESC);

		// On change, click or after pressing ENTER or TAB key, input the selects value into the input on a change within the list
		if (
			(eventType === 'change' ||
				eventType === 'click' ||
				(eventType === 'keydown' &&
					(event.keyCode === keyENTER || event.key === 'Tab'))) &&
			datalistSelect.value.length > 0 &&
			datalistSelect.value !== datalist.title
		) {
			setInputValue(input, datalistSelect.value);

			// Dispatch the input event on the related input[list]
			dispatchInputEvent(input);

			// Finally focusing the input, as other browser do this as well
			if (event.key !== 'Tab') {
				input.focus();
			}

			// #GH-51 / Prevent the form to be submitted on selecting a value via ENTER key within the select
			if (event.keyCode === keyENTER) {
				event.preventDefault();
			}

			// Set the visibility to false afterwards, as we're done here
			visible = false;
		} else if (eventType === 'keydown' && event.keyCode === keyESC) {
			// In case of the ESC key being pressed, we still want to focus the input[list]
			input.focus();
		}

		// Toggle the visibility of the datalist select according to previous checks
		toggleVisibility(visible, datalistSelect);
	}
934203
def OnGoToCell(self, event):
        """"""

        row, col, tab = event.key

        try:
            self.grid.actions.cursor = row, col, tab

        except ValueError:
            msg = _("Cell {key} outside grid shape {shape}").format(
                key=event.key, shape=self.grid.code_array.shape)
            post_command_event(self.grid.main_window, self.grid.StatusBarMsg,
                               text=msg)

            event.Skip()
            return

        self.grid.MakeCellVisible(row, col)

        event.Skip()
400779
function(e) {
        if (this.enableKeys) {
            var kc = Event.getCharCode(e);

            switch (kc) {
                case 0x25: // left
                case 0x26: // up
                case 0x27: // right
                case 0x28: // down
                case 0x24: // home
                case 0x23: // end
                    Event.preventDefault(e);
                    break;
                default:
            }
        }
    }
1249181
def on_left_click(self, event, grid, choices):
        
        color = self.grid.GetCellBackgroundColour(event.GetRow(), event.GetCol())
        # allow user to cherry-pick cells for editing.  gets selection of meta key for mac, ctrl key for pc
        if event.ControlDown() or event.MetaDown():
            row, col = event.GetRow(), event.GetCol()
            if (row, col) not in self.dispersed_selection:
                self.dispersed_selection.append((row, col))
                self.grid.SetCellBackgroundColour(row, col, 'light blue')
            else:
                self.dispersed_selection.remove((row, col))
                self.grid.SetCellBackgroundColour(row, col, color)# 'white'
            self.grid.ForceRefresh()
            return
        if event.ShiftDown(): # allow user to highlight multiple consecutive cells in a column
            previous_col = self.grid.GetGridCursorCol()
            previous_row = self.grid.GetGridCursorRow()
            col = event.GetCol()
            row = event.GetRow()
            if col != previous_col:
                return
            else:
                if row > previous_row:
                    row_range = list(range(previous_row, row+1))
                else:
                    row_range = list(range(row, previous_row+1))
            for r in row_range:
                self.grid.SetCellBackgroundColour(r, col, 'light blue')
                self.selection.append((r, col))
            self.grid.ForceRefresh()
            return

        selection = False

        if self.dispersed_selection:
            is_dispersed = True
            selection = self.dispersed_selection

        if self.selection:
            is_dispersed = False
            selection = self.selection

        try:
            col = event.GetCol()
            row = event.GetRow()
        except AttributeError:
            row, col = selection[0][0], selection[0][1]

        self.grid.SetGridCursor(row, col)

        if col in list(choices.keys()): # column should have a pop-up menu
            menu = wx.Menu()
            two_tiered = choices[col][1]
            choices = choices[col][0]
            if not two_tiered: # menu is one tiered
                if 'CLEAR cell of all values' not in choices:
                    choices.insert(0, 'CLEAR cell of all values')
                for choice in choices:
                    if not choice:
                        choice = " " # prevents error if choice is an empty string
                    menuitem = menu.Append(wx.ID_ANY, str(choice))
                    self.window.Bind(wx.EVT_MENU, lambda event: self.on_select_menuitem(event, grid, row, col, selection), menuitem)
                self.show_menu(event, menu)
            else: # menu is two_tiered
                clear = menu.Append(-1, 'CLEAR cell of all values')
                self.window.Bind(wx.EVT_MENU, lambda event: self.on_select_menuitem(event, grid, row, col, selection), clear)
                for choice in sorted(choices.items()):
                    submenu = wx.Menu()
                    for item in choice[1]:
                        menuitem = submenu.Append(-1, str(item))
                        self.window.Bind(wx.EVT_MENU, lambda event: self.on_select_menuitem(event, grid, row, col, selection), menuitem)
                    menu.Append(-1, choice[0], submenu)
                self.show_menu(event, menu)

        if selection:
            # re-whiten the cells that were previously highlighted
            for row, col in selection:
                self.grid.SetCellBackgroundColour(row, col, self.col_color)
            self.dispersed_selection = []
            self.selection = []
            self.grid.ForceRefresh()
1154542
def _cell_changed(self, *a):
        

        # block all signals during the update (to avoid re-calling this)
        self.block_events()

        # loop over the rows
        for n in range(self.get_row_count()):

            # get the keys and values (as text)
            key   = self.get_value(0,n)
            value = self.get_value(1,n)

            # get rid of the None's
            if key   == None:
                key = ''
                self.set_value(0,n, '')
            if value == None:
                value = ''
                self.set_value(1,n, '')

            # if it's not an empty entry make sure it's valid
            if not key == '':

                # clean up the key
                key = self._clean_up_key(key)

                # now make sure the value is python-able
                try:
                    eval(value)
                    self._widget.item(n,1).setData(_g.QtCore.Qt.BackgroundRole, _g.Qt.QtGui.QColor('white'))
                except:
                    self._widget.item(n,1).setData(_g.QtCore.Qt.BackgroundRole, _g.Qt.QtGui.QColor('pink'))

        # unblock all signals
        self.unblock_events()
1308723
public void onKeyDown (KeyDownEvent event)
    {
        if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
            _onEnter.onClick(null);
        }
    }
986641
function(_event){
                var _code = _event.keyCode;
                if (_code === 65 && _event[SELECT_ALL_MODIFIER] && !_event.shiftKey && !_event.altKey || // Ctrl-A or Cmd-A
                    _code >= 37 && _code <= 40 || // arrow key
                    _event.ctrlKey && MAC && MAC_MOVE_KEYS.indexOf(_code) >= 0) {
                  if (!HAS_OWN_SELECTION[_event.target.tagName]) {
                    setTimeout(_dispatchIfChanged.bind(null, this), 0);
                  }
                }
            }
82066
def on_saveButton(self, event, grid):
        """"""
        wait = wx.BusyInfo("Please wait, working...")
        wx.SafeYield()

        if self.grid_frame.drop_down_menu:  # unhighlight selected columns, etc.
            self.grid_frame.drop_down_menu.clean_up()

        # remove '**' and '^^' from col labels
        starred_cols, hatted_cols = grid.remove_starred_labels()

        grid.SaveEditControlValue() # locks in value in cell currently edited
        grid.HideCellEditControl() # removes focus from cell that was being edited

        if grid.changes:
            self.onSave(grid)

        for col in starred_cols:
            label = grid.GetColLabelValue(col)
            grid.SetColLabelValue(col, label + '**')
        for col in hatted_cols:
            label = grid.GetColLabelValue(col)
            grid.SetColLabelValue(col, label + '^^')
        del wait
786715
function(e) {
        var KEYS = YAHOO.util.KeyListener.KEY;

        if (YAHOO.util.Event.getCharCode(e) == KEYS.ENTER) {
            YAHOO.util.Event.preventDefault(e);
            this.submit();
        }
    }