cant replace data in serialized textview, bytearray size problem?
Im really struggling with serialized textbuffer data. I just got thru an SQL encoding issue(thanks theGtkNerd for the help.) and now my troubles are back.
Im trying to add search/replace functionality to a textview that is using pixbufs and formated text, since i have images/tags stored in the buffer, i am trying to do the replace on the serialized textview buffer data.
the following code works as long as the replace string is the same size as the searchstr.
def _diagFnRReplaceAll(self,oWidget): #Replace All Function
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(),
buf.get_end_iter())
sys.stdout.buffer.write(data) #< print raw for debugging
newdata = data.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii'))
print("nnnn")
sys.stdout.buffer.write(newdata) #< print raw for debugging
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),newdata)
if its smaller or larger i get the following error.
Gtk:ERROR:../../../../gtk/gtktextbufferserialize.c:1588:text_handler: code should not be reached
i tried changing the encoding type, and different ways to encode, but it didnt help. the fact that a same size string works fine makes me think there is a size value for the serialized buffer data or pixbuf data somewhere, but i havnt come up with anything by searching.
i tried to do the replace like you would on a textview without pics, it worked but lost the pic/format data.
Does anyone know why this is happening?
or does anyone know another way i can do a search and replace in a textview widget that has pixbuf data and formatting tags?
python serialization replace encoding gtk
add a comment |
Im really struggling with serialized textbuffer data. I just got thru an SQL encoding issue(thanks theGtkNerd for the help.) and now my troubles are back.
Im trying to add search/replace functionality to a textview that is using pixbufs and formated text, since i have images/tags stored in the buffer, i am trying to do the replace on the serialized textview buffer data.
the following code works as long as the replace string is the same size as the searchstr.
def _diagFnRReplaceAll(self,oWidget): #Replace All Function
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(),
buf.get_end_iter())
sys.stdout.buffer.write(data) #< print raw for debugging
newdata = data.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii'))
print("nnnn")
sys.stdout.buffer.write(newdata) #< print raw for debugging
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),newdata)
if its smaller or larger i get the following error.
Gtk:ERROR:../../../../gtk/gtktextbufferserialize.c:1588:text_handler: code should not be reached
i tried changing the encoding type, and different ways to encode, but it didnt help. the fact that a same size string works fine makes me think there is a size value for the serialized buffer data or pixbuf data somewhere, but i havnt come up with anything by searching.
i tried to do the replace like you would on a textview without pics, it worked but lost the pic/format data.
Does anyone know why this is happening?
or does anyone know another way i can do a search and replace in a textview widget that has pixbuf data and formatting tags?
python serialization replace encoding gtk
i think im making a little progress. it looks like the size of the array may be stored right in the contents of the buffer. here is the start line of the buffer: GTKTEXTBUFFERCONTENTS-0001L <text_view_markup> the L right after the 0001 changes with size. im going to experiment with modifying that and see what happens
– Brad
Nov 17 '18 at 21:36
If I remember right, I had this problem when I used iters for searching. I replaced iter usage with marks. Let me see if I can find my code again.
– theGtknerd
Nov 17 '18 at 23:55
Hopefully this helps. Iters get invalid after changing the buffer contents, therefore you need to use marks.
– theGtknerd
Nov 18 '18 at 2:20
add a comment |
Im really struggling with serialized textbuffer data. I just got thru an SQL encoding issue(thanks theGtkNerd for the help.) and now my troubles are back.
Im trying to add search/replace functionality to a textview that is using pixbufs and formated text, since i have images/tags stored in the buffer, i am trying to do the replace on the serialized textview buffer data.
the following code works as long as the replace string is the same size as the searchstr.
def _diagFnRReplaceAll(self,oWidget): #Replace All Function
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(),
buf.get_end_iter())
sys.stdout.buffer.write(data) #< print raw for debugging
newdata = data.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii'))
print("nnnn")
sys.stdout.buffer.write(newdata) #< print raw for debugging
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),newdata)
if its smaller or larger i get the following error.
Gtk:ERROR:../../../../gtk/gtktextbufferserialize.c:1588:text_handler: code should not be reached
i tried changing the encoding type, and different ways to encode, but it didnt help. the fact that a same size string works fine makes me think there is a size value for the serialized buffer data or pixbuf data somewhere, but i havnt come up with anything by searching.
i tried to do the replace like you would on a textview without pics, it worked but lost the pic/format data.
Does anyone know why this is happening?
or does anyone know another way i can do a search and replace in a textview widget that has pixbuf data and formatting tags?
python serialization replace encoding gtk
Im really struggling with serialized textbuffer data. I just got thru an SQL encoding issue(thanks theGtkNerd for the help.) and now my troubles are back.
Im trying to add search/replace functionality to a textview that is using pixbufs and formated text, since i have images/tags stored in the buffer, i am trying to do the replace on the serialized textview buffer data.
the following code works as long as the replace string is the same size as the searchstr.
def _diagFnRReplaceAll(self,oWidget): #Replace All Function
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(),
buf.get_end_iter())
sys.stdout.buffer.write(data) #< print raw for debugging
newdata = data.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii'))
print("nnnn")
sys.stdout.buffer.write(newdata) #< print raw for debugging
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),newdata)
if its smaller or larger i get the following error.
Gtk:ERROR:../../../../gtk/gtktextbufferserialize.c:1588:text_handler: code should not be reached
i tried changing the encoding type, and different ways to encode, but it didnt help. the fact that a same size string works fine makes me think there is a size value for the serialized buffer data or pixbuf data somewhere, but i havnt come up with anything by searching.
i tried to do the replace like you would on a textview without pics, it worked but lost the pic/format data.
Does anyone know why this is happening?
or does anyone know another way i can do a search and replace in a textview widget that has pixbuf data and formatting tags?
python serialization replace encoding gtk
python serialization replace encoding gtk
asked Nov 17 '18 at 19:27
BradBrad
1113
1113
i think im making a little progress. it looks like the size of the array may be stored right in the contents of the buffer. here is the start line of the buffer: GTKTEXTBUFFERCONTENTS-0001L <text_view_markup> the L right after the 0001 changes with size. im going to experiment with modifying that and see what happens
– Brad
Nov 17 '18 at 21:36
If I remember right, I had this problem when I used iters for searching. I replaced iter usage with marks. Let me see if I can find my code again.
– theGtknerd
Nov 17 '18 at 23:55
Hopefully this helps. Iters get invalid after changing the buffer contents, therefore you need to use marks.
– theGtknerd
Nov 18 '18 at 2:20
add a comment |
i think im making a little progress. it looks like the size of the array may be stored right in the contents of the buffer. here is the start line of the buffer: GTKTEXTBUFFERCONTENTS-0001L <text_view_markup> the L right after the 0001 changes with size. im going to experiment with modifying that and see what happens
– Brad
Nov 17 '18 at 21:36
If I remember right, I had this problem when I used iters for searching. I replaced iter usage with marks. Let me see if I can find my code again.
– theGtknerd
Nov 17 '18 at 23:55
Hopefully this helps. Iters get invalid after changing the buffer contents, therefore you need to use marks.
– theGtknerd
Nov 18 '18 at 2:20
i think im making a little progress. it looks like the size of the array may be stored right in the contents of the buffer. here is the start line of the buffer: GTKTEXTBUFFERCONTENTS-0001L <text_view_markup> the L right after the 0001 changes with size. im going to experiment with modifying that and see what happens
– Brad
Nov 17 '18 at 21:36
i think im making a little progress. it looks like the size of the array may be stored right in the contents of the buffer. here is the start line of the buffer: GTKTEXTBUFFERCONTENTS-0001L <text_view_markup> the L right after the 0001 changes with size. im going to experiment with modifying that and see what happens
– Brad
Nov 17 '18 at 21:36
If I remember right, I had this problem when I used iters for searching. I replaced iter usage with marks. Let me see if I can find my code again.
– theGtknerd
Nov 17 '18 at 23:55
If I remember right, I had this problem when I used iters for searching. I replaced iter usage with marks. Let me see if I can find my code again.
– theGtknerd
Nov 17 '18 at 23:55
Hopefully this helps. Iters get invalid after changing the buffer contents, therefore you need to use marks.
– theGtknerd
Nov 18 '18 at 2:20
Hopefully this helps. Iters get invalid after changing the buffer contents, therefore you need to use marks.
– theGtknerd
Nov 18 '18 at 2:20
add a comment |
1 Answer
1
active
oldest
votes
well i got it wotking using a little byte patching.I just saw your comment on using marks, i will look into that as i would rather use builtin functionality instead of what im doing. My way is replacing the 4 bytes after the GTKBUFFERCONTENTS-001 with a new 4 byte value for the new size of the buffer.
here is what i have working right now
def _diagFnRReplaceAll(self,oWidget):
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(), buf.get_end_iter())
start_bytes = data[0:26]
size_bytes =data[26:30]
sizeval = int.from_bytes(size_bytes, byteorder='big', signed=False)
end_of_markup = 29 + sizeval +1
the_rest = data[end_of_markup:len(data)]
markup = data[30:end_of_markup]
newmarkup = bytearray(markup.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii')))
newsize = len(newmarkup).to_bytes(4,'big')
reconstruct =start_bytes + newsize + newmarkup +the_rest
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),reconstruct)
This works without issue so far, i will repost if i get it working with the 'Marks' suggestion. Thanks again theGtknerd.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354763%2fcant-replace-data-in-serialized-textview-bytearray-size-problem%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
well i got it wotking using a little byte patching.I just saw your comment on using marks, i will look into that as i would rather use builtin functionality instead of what im doing. My way is replacing the 4 bytes after the GTKBUFFERCONTENTS-001 with a new 4 byte value for the new size of the buffer.
here is what i have working right now
def _diagFnRReplaceAll(self,oWidget):
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(), buf.get_end_iter())
start_bytes = data[0:26]
size_bytes =data[26:30]
sizeval = int.from_bytes(size_bytes, byteorder='big', signed=False)
end_of_markup = 29 + sizeval +1
the_rest = data[end_of_markup:len(data)]
markup = data[30:end_of_markup]
newmarkup = bytearray(markup.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii')))
newsize = len(newmarkup).to_bytes(4,'big')
reconstruct =start_bytes + newsize + newmarkup +the_rest
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),reconstruct)
This works without issue so far, i will repost if i get it working with the 'Marks' suggestion. Thanks again theGtknerd.
add a comment |
well i got it wotking using a little byte patching.I just saw your comment on using marks, i will look into that as i would rather use builtin functionality instead of what im doing. My way is replacing the 4 bytes after the GTKBUFFERCONTENTS-001 with a new 4 byte value for the new size of the buffer.
here is what i have working right now
def _diagFnRReplaceAll(self,oWidget):
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(), buf.get_end_iter())
start_bytes = data[0:26]
size_bytes =data[26:30]
sizeval = int.from_bytes(size_bytes, byteorder='big', signed=False)
end_of_markup = 29 + sizeval +1
the_rest = data[end_of_markup:len(data)]
markup = data[30:end_of_markup]
newmarkup = bytearray(markup.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii')))
newsize = len(newmarkup).to_bytes(4,'big')
reconstruct =start_bytes + newsize + newmarkup +the_rest
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),reconstruct)
This works without issue so far, i will repost if i get it working with the 'Marks' suggestion. Thanks again theGtknerd.
add a comment |
well i got it wotking using a little byte patching.I just saw your comment on using marks, i will look into that as i would rather use builtin functionality instead of what im doing. My way is replacing the 4 bytes after the GTKBUFFERCONTENTS-001 with a new 4 byte value for the new size of the buffer.
here is what i have working right now
def _diagFnRReplaceAll(self,oWidget):
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(), buf.get_end_iter())
start_bytes = data[0:26]
size_bytes =data[26:30]
sizeval = int.from_bytes(size_bytes, byteorder='big', signed=False)
end_of_markup = 29 + sizeval +1
the_rest = data[end_of_markup:len(data)]
markup = data[30:end_of_markup]
newmarkup = bytearray(markup.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii')))
newsize = len(newmarkup).to_bytes(4,'big')
reconstruct =start_bytes + newsize + newmarkup +the_rest
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),reconstruct)
This works without issue so far, i will repost if i get it working with the 'Marks' suggestion. Thanks again theGtknerd.
well i got it wotking using a little byte patching.I just saw your comment on using marks, i will look into that as i would rather use builtin functionality instead of what im doing. My way is replacing the 4 bytes after the GTKBUFFERCONTENTS-001 with a new 4 byte value for the new size of the buffer.
here is what i have working right now
def _diagFnRReplaceAll(self,oWidget):
findbox = self.builder.get_object('FnRFindEntry')
searchstr = findbox.get_text()
buf = self.dataview.get_buffer()
repbox = self.builder.get_object('FnRReplaceEntry')
repstr = repbox.get_text()
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(), buf.get_end_iter())
start_bytes = data[0:26]
size_bytes =data[26:30]
sizeval = int.from_bytes(size_bytes, byteorder='big', signed=False)
end_of_markup = 29 + sizeval +1
the_rest = data[end_of_markup:len(data)]
markup = data[30:end_of_markup]
newmarkup = bytearray(markup.replace(bytes(searchstr,'ascii'),bytes(repstr,'ascii')))
newsize = len(newmarkup).to_bytes(4,'big')
reconstruct =start_bytes + newsize + newmarkup +the_rest
buf.set_text('')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(),reconstruct)
This works without issue so far, i will repost if i get it working with the 'Marks' suggestion. Thanks again theGtknerd.
answered Nov 18 '18 at 15:26
BradBrad
1113
1113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354763%2fcant-replace-data-in-serialized-textview-bytearray-size-problem%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
i think im making a little progress. it looks like the size of the array may be stored right in the contents of the buffer. here is the start line of the buffer: GTKTEXTBUFFERCONTENTS-0001L <text_view_markup> the L right after the 0001 changes with size. im going to experiment with modifying that and see what happens
– Brad
Nov 17 '18 at 21:36
If I remember right, I had this problem when I used iters for searching. I replaced iter usage with marks. Let me see if I can find my code again.
– theGtknerd
Nov 17 '18 at 23:55
Hopefully this helps. Iters get invalid after changing the buffer contents, therefore you need to use marks.
– theGtknerd
Nov 18 '18 at 2:20