(self, text)
change data
change data
change data
def modify_data(self, text):
        """ change data
        """
        current_byte = self.data[self.caret.position]
        _byte = 0

        # caret is hextype so allow nibble editing
        if self.caret.mode == 'hex':
            if self.caret.nibble == 1:
                _byte = (current_byte & 0xf0) | self._hex_chars.index(text)
                self.caret.nibble = 0
            else:
                _byte = (current_byte & 0x0f) | (
                        self._hex_chars.index(text) << 4)
                self.caret.nibble = 1
        # caret is asciitype try byteconv
        elif self.caret.mode == 'ascii':
            try:
                _byte = int(bytearray(text, 'utf8')[0])
            except ValueError:
                self.display_error('something is wrong')
                return
        else:
            return

        # change byte in data
        data_bt = bytearray(self.data)
        data_bt[self.caret.position] = _byte
        self.data = bytes(data_bt)

        # emit datachanged
        self.dataChanged.emit(self.caret.position, 1)

        # add highlight
        try:
            is_highlight = self.is_highlighted(self.caret.position + self.base)
            if not is_highlight:
                self.add_highlight(
                    HighLight('edited', self.caret.position + self.base, 1))
        except HighlightExistsError:
            pass

        # move cursor when and repaint
        if self.caret.mode == 'hex':
            # dont move to next byte when in nibbleedit
            if self.caret.nibble == 0:
                self.caret.move_right(len(self.data))
        elif self.caret.mode == 'ascii':
            self.caret.move_right(len(self.data))
        self._force_repaint(True)
def modify_data ( self , text ) : current_byte = self . data [ self . caret . position ] _byte = 0 # caret is hextype so allow nibble editing if self . caret . mode == 'hex' : if self . caret . nibble == 1 : _byte = ( current_byte & 0xf0 ) | self . _hex_chars . index ( text ) self . caret . nibble = 0 else : _byte = ( current_byte & 0x0f ) | ( self . _hex_chars . index ( text ) << 4 ) self . caret . nibble = 1 # caret is asciitype try byteconv elif self . caret . mode == 'ascii' : try : _byte = int ( bytearray ( text , 'utf8' ) [ 0 ] ) except ValueError : self . display_error ( 'something is wrong' ) return else : return # change byte in data data_bt = bytearray ( self . data ) data_bt [ self . caret . position ] = _byte self . data = bytes ( data_bt ) # emit datachanged self . dataChanged . emit ( self . caret . position , 1 ) # add highlight try : is_highlight = self . is_highlighted ( self . caret . position + self . base ) if not is_highlight : self . add_highlight ( HighLight ( 'edited' , self . caret . position + self . base , 1 ) ) except HighlightExistsError : pass # move cursor when and repaint if self . caret . mode == 'hex' : # dont move to next byte when in nibbleedit if self . caret . nibble == 0 : self . caret . move_right ( len ( self . data ) ) elif self . caret . mode == 'ascii' : self . caret . move_right ( len ( self . data ) ) self . _force_repaint ( True )