mssever
December 18th, 2008, 10:45 PM
A utility I'm writing includes a gtk.Entry whose default value is the clipboard contents. Since the clipboard contents won't always fit in the Entry without scrolling, and since the most important information is at the beginning of the string, I want the first character to be visible (plus whatever other characters fit).
My approach to this has been to try to set the cursor to position 0 (the Entry has input focus by default). However, this test code produces weird results:
# self.text_entry is an instance of gtk.Entry
self.text_entry.paste_clipboard()
print self.text_entry.get_position()
self.text_entry.set_position(0)
self.text_entry.insert_text('test',0)
print self.text_entry.get_position()The printed results are:
0
0Furthermore, the word "test" appears after the pasted text, but the cursor is immediately before the word "test". So not only is the cursor not getting moved, but get_position() is reporting incorrect values. What's wrong?
EDIT: I've attached a screenshot showing the state after the code snippets above have run.
My approach to this has been to try to set the cursor to position 0 (the Entry has input focus by default). However, this test code produces weird results:
# self.text_entry is an instance of gtk.Entry
self.text_entry.paste_clipboard()
print self.text_entry.get_position()
self.text_entry.set_position(0)
self.text_entry.insert_text('test',0)
print self.text_entry.get_position()The printed results are:
0
0Furthermore, the word "test" appears after the pasted text, but the cursor is immediately before the word "test". So not only is the cursor not getting moved, but get_position() is reporting incorrect values. What's wrong?
EDIT: I've attached a screenshot showing the state after the code snippets above have run.