From 519f43c6c23ccb9ed54d164fcff90e5dcf722335 Mon Sep 17 00:00:00 2001 From: Richard Taylor Date: Tue, 17 Jan 2006 15:07:01 +0000 Subject: [PATCH] () -> [], add IntEdit svn: r5776 --- src/GrampsWidgets.py | 29 ++++++++++++++ src/ObjectSelector/_FamilyFilterFrame.py | 2 +- src/ObjectSelector/_FamilyFrame.py | 2 +- src/ObjectSelector/_IntEdit.py | 49 ------------------------ src/ObjectSelector/_PersonFilterFrame.py | 2 +- src/ObjectSelector/_PersonFrame.py | 2 +- 6 files changed, 33 insertions(+), 53 deletions(-) delete mode 100644 src/ObjectSelector/_IntEdit.py diff --git a/src/GrampsWidgets.py b/src/GrampsWidgets.py index f804f1eec..48712ddcb 100644 --- a/src/GrampsWidgets.py +++ b/src/GrampsWidgets.py @@ -111,3 +111,32 @@ class MarkupLabel(gtk.Label): self.show() +class IntEdit(gtk.Entry): + """An gtk.Edit widget that only allows integers.""" + + def __init__(self): + gtk.Entry.__init__(self) + + self._signal = self.connect("insert_text", self.insert_cb) + + def insert_cb(self, widget, text, length, *args): + # if you don't do this, garbage comes in with text + text = text[:length] + pos = widget.get_position() + # stop default emission + widget.emit_stop_by_name("insert_text") + gobject.idle_add(self.insert, widget, text, pos) + + def insert(self, widget, text, pos): + if len(text) > 0 and text.isdigit(): + # the next three lines set up the text. this is done because we + # can't use insert_text(): it always inserts at position zero. + orig_text = widget.get_text() + new_text = orig_text[:pos] + text + orig_text[pos:] + # avoid recursive calls triggered by set_text + widget.handler_block(self._signal) + # replace the text with some new text + widget.set_text(new_text) + widget.handler_unblock(self._signal) + # set the correct position in the widget + widget.set_position(pos + len(text)) diff --git a/src/ObjectSelector/_FamilyFilterFrame.py b/src/ObjectSelector/_FamilyFilterFrame.py index 8fd22b844..cd1395b5a 100644 --- a/src/ObjectSelector/_FamilyFilterFrame.py +++ b/src/ObjectSelector/_FamilyFilterFrame.py @@ -1,7 +1,7 @@ import gtk import gobject -from _IntEdit import IntEdit +from GrampsWidgets import IntEdit class FamilyFilterFrame(gtk.Frame): diff --git a/src/ObjectSelector/_FamilyFrame.py b/src/ObjectSelector/_FamilyFrame.py index 7dd97f60e..fd5bae06d 100644 --- a/src/ObjectSelector/_FamilyFrame.py +++ b/src/ObjectSelector/_FamilyFrame.py @@ -45,7 +45,7 @@ class FamilyFrame(ObjectFrameBase): def _handle_selection(self,treeselection): (model, iter) = treeselection.get_selected() if iter and model.get_value(iter,self.__class__.__person_id_field): - self.emit('selection-changed', "%s / %s (%s)" % ( + self.emit('selection-changed', "%s / %s [%s]" % ( str(model.get_value(iter,1)), str(model.get_value(iter,2)), str(model.get_value(iter,0))), diff --git a/src/ObjectSelector/_IntEdit.py b/src/ObjectSelector/_IntEdit.py deleted file mode 100644 index 9f125d37d..000000000 --- a/src/ObjectSelector/_IntEdit.py +++ /dev/null @@ -1,49 +0,0 @@ -import gtk -import gobject - -class IntEdit(gtk.Entry): - """An gtk.Edit widget that only allows integers.""" - - __gproperties__ = {} - - __gsignals__ = { - } - - def __init__(self): - gtk.Entry.__init__(self) - - self._signal = self.connect("insert_text", self.insert_cb) - - def insert_cb(self, widget, text, length, *args): - # if you don't do this, garbage comes in with text - text = text[:length] - pos = widget.get_position() - # stop default emission - widget.emit_stop_by_name("insert_text") - gobject.idle_add(self.insert, widget, text, pos) - - def insert(self, widget, text, pos): - if len(text) > 0 and text.isdigit(): - # the next three lines set up the text. this is done because we - # can't use insert_text(): it always inserts at position zero. - orig_text = widget.get_text() - new_text = orig_text[:pos] + text + orig_text[pos:] - # avoid recursive calls triggered by set_text - widget.handler_block(self._signal) - # replace the text with some new text - widget.set_text(new_text) - widget.handler_unblock(self._signal) - # set the correct position in the widget - widget.set_position(pos + len(text)) - -if gtk.pygtk_version < (2,8,0): - gobject.type_register(IntEdit) - -if __name__ == "__main__": - - w = gtk.Window() - f = IntEdit() - w.add(f) - w.show_all() - - gtk.main() diff --git a/src/ObjectSelector/_PersonFilterFrame.py b/src/ObjectSelector/_PersonFilterFrame.py index 7869ae26c..63f773211 100644 --- a/src/ObjectSelector/_PersonFilterFrame.py +++ b/src/ObjectSelector/_PersonFilterFrame.py @@ -1,7 +1,7 @@ import gtk import gobject -from _IntEdit import IntEdit +from GrampsWidgets import IntEdit class PersonFilterFrame(gtk.Frame): diff --git a/src/ObjectSelector/_PersonFrame.py b/src/ObjectSelector/_PersonFrame.py index ade75c350..02af87596 100644 --- a/src/ObjectSelector/_PersonFrame.py +++ b/src/ObjectSelector/_PersonFrame.py @@ -40,7 +40,7 @@ class PersonFrame(ObjectFrameBase): def handle_selection(treeselection): (model, iter) = treeselection.get_selected() if iter and model.get_value(iter,1): - self.emit('selection-changed', "%s (%s)" % ( + self.emit('selection-changed', "%s [%s]" % ( str(model.get_value(iter,0)), str(model.get_value(iter,1))), model.get_value(iter,1))