() -> [], add IntEdit

svn: r5776
This commit is contained in:
Richard Taylor 2006-01-17 15:07:01 +00:00
parent d5ec08247d
commit 519f43c6c2
6 changed files with 33 additions and 53 deletions

View File

@ -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))

View File

@ -1,7 +1,7 @@
import gtk
import gobject
from _IntEdit import IntEdit
from GrampsWidgets import IntEdit
class FamilyFilterFrame(gtk.Frame):

View File

@ -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))),

View File

@ -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()

View File

@ -1,7 +1,7 @@
import gtk
import gobject
from _IntEdit import IntEdit
from GrampsWidgets import IntEdit
class PersonFilterFrame(gtk.Frame):

View File

@ -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))