def cmd_get_text(self, arguments): buff_name = arguments['buff_name'] start = messaging.messarg2int(arguments['start']) end = messaging.messarg2int(arguments['end']) value = self.editor.get_text(start = start, end = end, buff_name = buff_name) self.send_response('get_text_resp', value)
def cmd_goto_line(self, arguments): buff_name = arguments['buff_name'] linenum = messaging.messarg2int(arguments['linenum']) where = messaging.messarg2int(arguments['where']) self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.goto_line(linenum, where, buff_name=buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('goto_line_resp', updates)
def cmd_goto_line(self, arguments): buff_name = arguments['buff_name'] linenum = messaging.messarg2int(arguments['linenum']) where = messaging.messarg2int(arguments['where']) self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.goto_line(linenum, where, buff_name = buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('goto_line_resp', updates)
def cmd_set_text(self, arguments): buff_name = arguments['buff_name'] text = arguments['text'] start = messaging.messarg2int(arguments['start']) end = messaging.messarg2int(arguments['end']) # print start, end self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.set_text(text, start=start, end=end, buff_name=buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('set_text_resp', updates)
def cmd_set_selection(self, arguments): buff_name = arguments['buff_name'] range = messaging.messarg2inttuple(arguments['range']) cursor_at = messaging.messarg2int(arguments['cursor_at']) self.editor.set_selection(range, cursor_at, buff_name=buff_name) updates = self.pos_selection_update(buff_name) self.send_updates_response('set_selection_resp', updates)
def find_matching(self, direction = 1): """ Finds a matching brace/bracket/parenthesis. NOTE: this method does not find matching quotes, or any other character where the opening and closing characters are identical ** INPUTS ** *INT direction* -- direction of the search. Direction = 1 means to search forward for the character matching the one at the current cursor position. Direction = minus 1 means to search backward for the character matching the one before the current cursor position. ** OUTPUTS ** *INT* -- the position of the matching character, or if the character adjacent to the cursor was not a bracket, brace, or parenthesis, or if no matching character could be found """ self.app.talk_msgr.send_mess('find_matching', {'buff_name': self.buff_name, 'direction': direction}) response = self.app.talk_msgr.get_mess(expect = ['find_matching_resp']) return messaging.messarg2int(response[1]['value'])
def _get_pos_selection_from_app(self): """retrieves current position of cursor and the range of current selection directly from the external application **INPUTS** *none* **OUTPUTS** *(INT, (INT, INT))* (pos, (start, end)) pos is the offset into buffer of current cursor position start is the offset into the buffer of the start of the current selection. end is the offset into the buffer of the character following the selection (this matches Python's slice convention). """ self.app.talk_msgr.send_mess('get_pos_selection', {'buff_name': self.name()}) response = self.app.talk_msgr.get_mess( expect=['get_pos_selection_resp']) value = response[1]['value'] trace('SourceBuffMessaging._get_pos_selection_from_app', 'value = %s' % value) pos = messaging.messarg2int(value['pos']) trace('SourceBuffMessaging._get_pos_selection_from_app', 'pos = %d' % pos) selection = messaging.messarg2inttuple(value['selection']) trace('SourceBuffMessaging._get_pos_selection_from_app', 'selection = %s' % repr(selection)) return (pos, selection)
def cmd_set_text(self, arguments): buff_name = arguments['buff_name'] text = arguments['text'] start = messaging.messarg2int(arguments['start']) end = messaging.messarg2int(arguments['end']) # print start, end self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.set_text(text, start = start, end = end, buff_name = buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('set_text_resp', updates)
def _get_pos_selection_from_app(self): """retrieves current position of cursor and the range of current selection directly from the external application **INPUTS** *none* **OUTPUTS** *(INT, (INT, INT))* (pos, (start, end)) pos is the offset into buffer of current cursor position start is the offset into the buffer of the start of the current selection. end is the offset into the buffer of the character following the selection (this matches Python's slice convention). """ self.app.talk_msgr.send_mess('get_pos_selection', {'buff_name': self.name()}) response = self.app.talk_msgr.get_mess(expect=['get_pos_selection_resp']) value = response[1]['value'] trace('SourceBuffMessaging._get_pos_selection_from_app', 'value = %s' % value) pos = messaging.messarg2int(value['pos']) trace('SourceBuffMessaging._get_pos_selection_from_app', 'pos = %d' % pos) selection = messaging.messarg2inttuple(value['selection']) trace('SourceBuffMessaging._get_pos_selection_from_app', 'selection = %s' % repr(selection)) return (pos, selection)
def cmd_set_selection(self, arguments): buff_name = arguments['buff_name'] range = messaging.messarg2inttuple(arguments['range']) cursor_at = messaging.messarg2int(arguments['cursor_at']) self.editor.set_selection(range, cursor_at, buff_name = buff_name) updates = self.pos_selection_update(buff_name) self.send_updates_response('set_selection_resp', updates)
def cmd_close_buffer(self, arguments): # print 'client received close buffer command with arguments', arguments buff_name = arguments['buff_name'] save = messaging.messarg2int(arguments['save']) self.ignore_callbacks = 1 success = self.editor.app_close_buffer(buff_name, save) self.ignore_callbacks = 0 self.send_response('close_buffer_resp', success)
def cmd_goto(self, arguments): buff_name = arguments['buff_name'] pos = messaging.messarg2int(arguments['pos']) self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.goto(pos, buff_name=buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('goto_resp', updates)
def cmd_goto(self, arguments): buff_name = arguments['buff_name'] pos = messaging.messarg2int(arguments['pos']) self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.goto(pos, buff_name = buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('goto_resp', updates)
def cmd_backspace(self, arguments): buff_name = arguments['buff_name'] n_times = messaging.messarg2int(arguments['n_times']) self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.backspace(n_times, buff_name=buff_name) self.editor.print_buff_if_necessary(buff_name=buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('backspace_resp', updates)
def cmd_backspace(self, arguments): buff_name = arguments['buff_name'] n_times = messaging.messarg2int(arguments['n_times']) self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.backspace(n_times, buff_name = buff_name) self.editor.print_buff_if_necessary(buff_name = buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('backspace_resp', updates)
def cmd_decr_indent_level(self, arguments): buff_name = arguments['buff_name'] levels = messaging.messarg2int(arguments['levels']) range = messaging.messarg2inttuple(arguments['range']) self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.decr_indent_level(levels, range, buff_name=buff_name) self.editor.print_buff_if_necessary(buff_name=buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('decr_indent_level_resp', updates)
def cmd_decr_indent_level(self, arguments): buff_name = arguments['buff_name'] levels = messaging.messarg2int(arguments['levels']) range = messaging.messarg2inttuple(arguments['range']) self.awaiting_response = [] b_name = buff_name if b_name == None: b_name = self.editor.curr_buffer() self.editor.decr_indent_level(levels, range, buff_name = buff_name) self.editor.print_buff_if_necessary(buff_name = buff_name) updates = self.awaiting_response self.awaiting_response = None updates = updates + self.pos_selection_update(b_name) self.send_updates_response('decr_indent_level_resp', updates)
def _len_from_app(self): """return length of buffer in characters. **INPUTS** *none* **OUTPUTS** *INT* length """ self.app.talk_msgr.send_mess('len', {'buff_name': self.name()}) response = self.app.talk_msgr.get_mess(expect=['len_resp']) return messaging.messarg2int(response[1]['value'])
def line_num_of(self, position=None): """ Returns the line number for a particular cursor position **INPUTS** *INT* position -- The position. (defaults to the current position) **OUTPUTS** *INT line_num* -- The line number of that position """ args = {'position': position, 'buff_name': self.name()} self.app.talk_msgr.send_mess('line_num_of', args) response = self.app.talk_msgr.get_mess(expect=['line_num_of_resp']) return messaging.messarg2int(response[1]['value'])
def line_num_of(self, position = None): """ Returns the line number for a particular cursor position **INPUTS** *INT* position -- The position. (defaults to the current position) **OUTPUTS** *INT line_num* -- The line number of that position """ args = {'position': position, 'buff_name': self.name()} self.app.talk_msgr.send_mess('line_num_of', args) response = self.app.talk_msgr.get_mess(expect=['line_num_of_resp']) return messaging.messarg2int(response[1]['value'])
def end_of_line(self, pos = None): """Returns the position of the end of line at position *pos* **INPUTS** *INT* pos -- Position for which we want to know the end of line. **OUTPUTS** *INT* end_pos -- Position of the end of the line """ args = {'pos': pos, 'buff_name': self.name()} self.app.talk_msgr.send_mess('end_of_line', args) response = \ self.app.talk_msgr.get_mess(expect=['end_of_line_resp']) return messaging.messarg2int(response[1]['value'])
def end_of_line(self, pos=None): """Returns the position of the end of line at position *pos* **INPUTS** *INT* pos -- Position for which we want to know the end of line. **OUTPUTS** *INT* end_pos -- Position of the end of the line """ args = {'pos': pos, 'buff_name': self.name()} self.app.talk_msgr.send_mess('end_of_line', args) response = \ self.app.talk_msgr.get_mess(expect=['end_of_line_resp']) return messaging.messarg2int(response[1]['value'])
def app_change_buffer(self, buff_name): """Changes the external application's active buffer. **INPUTS** STR *buff_name* -- Name of the buffer to switch to. **OUTPUTS** *BOOL* -- true if buff_name exists and the application successfully switches to it """ self.talk_msgr.send_mess('change_buff', {'buff_name': buff_name}) response = self.talk_msgr.get_mess(expect=['change_buff_resp']) value = messaging.messarg2int(response[1]['value']) if tracing('AppStateEmacs.app_change_buffer'): trace('AppStateEmacs.app_change_buffer', 'response was %d' % value) return value
def recog_begin(self, window_id, block=0): """Invoked at the beginning of a recognition event. The editor then returns telling VoiceCode whether or not the user is allowed to speak into window *window_id*. **INPUTS** INT *window_id* -- The ID of the window that was active when the recognition began. *BOOL block* -- true if the speech engine can detect recog_end events reliably. If so, and if the editor is capable of doing so, the editor may (at its discretion) also stop responding to user input until method [recog_end()] is invoked. This is to prevent a bunch of problems that can arise if the user types while VoiceCode is still processing an utterance. In such cases, the results of the utterance interpretation can be unpredictable, especially when it comes to correction. **NOTE:** However, if block is false, the editor **MUST NOT** stop responding, because the mediator will not be able to use recog_end to tell it to resume responding to user input. Also, the editor must provide a way for the user to re-enable input manually, in case the mediator crashes. If it cannot do so, it should not stop responding, regardless of the value of block. **OUTPUTS** BOOL *can_talk* -- *true* iif editor allows user to speak into window with ID *window_id* .. [recog_end()] file:///./AppState.AppState.html#recog_end""" self.talk_msgr.send_mess('recog_begin', { 'window_id': window_id, 'block': block }) response = self.talk_msgr.get_mess(expect=['recog_begin_resp']) return messaging.messarg2int(response[1]['value'])
def recog_begin(self, window_id, block = 0): """Invoked at the beginning of a recognition event. The editor then returns telling VoiceCode whether or not the user is allowed to speak into window *window_id*. **INPUTS** INT *window_id* -- The ID of the window that was active when the recognition began. *BOOL block* -- true if the speech engine can detect recog_end events reliably. If so, and if the editor is capable of doing so, the editor may (at its discretion) also stop responding to user input until method [recog_end()] is invoked. This is to prevent a bunch of problems that can arise if the user types while VoiceCode is still processing an utterance. In such cases, the results of the utterance interpretation can be unpredictable, especially when it comes to correction. **NOTE:** However, if block is false, the editor **MUST NOT** stop responding, because the mediator will not be able to use recog_end to tell it to resume responding to user input. Also, the editor must provide a way for the user to re-enable input manually, in case the mediator crashes. If it cannot do so, it should not stop responding, regardless of the value of block. **OUTPUTS** BOOL *can_talk* -- *true* iif editor allows user to speak into window with ID *window_id* .. [recog_end()] file:///./AppState.AppState.html#recog_end""" self.talk_msgr.send_mess('recog_begin', {'window_id': window_id, 'block': block}) response = self.talk_msgr.get_mess(expect=['recog_begin_resp']) return messaging.messarg2int(response[1]['value'])
def beginning_of_statement(self): """Finds the location of the beginning of the current statement NOTE: initially, this method maybe implemented using the external editor, said the exact definition of the current statement and where it starts may vary. ** INPUTS ** *none* ** OUTPUTS ** *INT* -- the position of the beginning of the statement found at the cursor position """ self.app.talk_msgr.send_mess('beginning_of_statement', {'buff_name': self.buff_name}) response = \ self.app.talk_msgr.get_mess(expect = ['beginning_of_statement_resp']) return messaging.messarg2int(response[1]['value'])
def cmd_recog_begin(self, arguments): window_id = messaging.messarg2int(arguments['window_id']) block = messaging.messarg2int(arguments['block']) value = self.editor.recog_begin(window_id, block) self.send_response('recog_begin_resp', value)
def cmd_line_num_of(self, arguments): buff_name = arguments['buff_name'] # print arguments position = messaging.messarg2int(arguments['position']) value = self.editor.line_num_of(position = position, buff_name = buff_name) self.send_response('line_num_of_resp', value)
def cmd_end_of_line(self, arguments): buff_name = arguments['buff_name'] pos = messaging.messarg2int(arguments['pos']) value = self.editor.end_of_line(pos = pos, buff_name = buff_name) self.send_response('end_of_line_resp', value)
def cmd_line_num_of(self, arguments): buff_name = arguments['buff_name'] # print arguments position = messaging.messarg2int(arguments['position']) value = self.editor.line_num_of(position=position, buff_name=buff_name) self.send_response('line_num_of_resp', value)
def cmd_end_of_line(self, arguments): buff_name = arguments['buff_name'] pos = messaging.messarg2int(arguments['pos']) value = self.editor.end_of_line(pos=pos, buff_name=buff_name) self.send_response('end_of_line_resp', value)
def cmd_get_text(self, arguments): buff_name = arguments['buff_name'] start = messaging.messarg2int(arguments['start']) end = messaging.messarg2int(arguments['end']) value = self.editor.get_text(start=start, end=end, buff_name=buff_name) self.send_response('get_text_resp', value)