I have created TreeView() table with pygtk in my script. In that one column textbox is as password type and if I type password it is showing character but password should be confidential. so I want, when I type password it show me just like as invisible (*).
My code is written below
# columns
(
COLUMN_EDITABLE,
COLUMN_USER,
COLUMN_PSW,
) = range(3)
model = gtk.ListStore(
gobject.TYPE_BOOLEAN,
gobject.TYPE_STRING,
gobject.TYPE_STRING,
)
treeview = gtk.TreeView(model)
#Password column
renderer = gtk.CellRendererText()
renderer.set_property('cell-background', '#efefef')
renderer.set_fixed_size(120,20)
renderer.connect("edited", self.on_cell_edited, model)
renderer.set_data("column", COLUMN_PSW)
column = gtk.TreeViewColumn("Password", renderer, text=COLUMN_PSW,
editable=COLUMN_EDITABLE)
treeview.append_column(column)
Now any one suggest me for this problem, what i do
Thanks in advance..
You need to connect to the editing-started
signal of the text renderer and set the visibility
property of the GtkEditable to False
in the handler. To avoid displaying the password when the user has finished editing it you should set the text
property to a fixed string and clear the contents of the editable in the editing-started
handler.
def on_cell_edited_started(self, cell, editable, path):
editable.delete_text(0, -1)
editable.set_visibility(False)
and then in __init__
self.renderer.set_property("text", "*****")
self.renderer.connect("editing-started", self.on_cell_editing_started)
Update:
I cannot reproduce your problem with the text showing after the ***
. I've modified your code as follows. when I click to edit the text is cleared and when I finish editing it goes back to ***
Callbacks:
def on_cell_editing_started(self,cell, editable, path):
editable.delete_text(0,-1)
editable.set_visibility(False)
def on_cell_edited(self, renderer, path, new_text, model):
iter = model.get_iter(path)
model.set_value(iter, COLUMN_PSW, new_text)
Setting up the renderer:
# psw column
self.renderer = gtk.CellRendererText()
self.renderer.connect("editing-started", self.on_cell_editing_started)
self.renderer.connect("edited", self.on_cell_edited, model)
self.renderer.set_property("text", "***")
column = gtk.TreeViewColumn("Password", self.renderer ,editable=COLUMN_EDITABLE)
treeview.append_column(column)
sw.add(treeview)
self.show_all()
Everything else is as in the latest file you shared. I suspect you've somehow set the text
property of the renderer with set_property
and also bound a column to it as well. I'm going to be off-line for the next 10 days or so, if your still having problems have a careful read of the documentation and double check you code so you understand what each line is doing.