Im working on an inventory manager script, i had this function working fine until i changed a text field to a textview. The way it needs to function is that when i try and edit an item it will fill in the information from a list on the previous dialog box. Heres the code:
Code:
def on_EditItem(self, widget):
"""Called when the user wants to edit an item entry"""
# Get the selection in the gtk.TreeView
selection = self.itemView.get_selection()
# Get the selection iter
model, selection_iter = selection.get_selected()
if (selection_iter):
"""There is a selection, so now get the the value at column
self.cItemObject, the Item Object"""
item = self.itemList.get_value(selection_iter, self.cItemObject)
# Create the item dialog, based off of the current selection
itemDlg = itemDialog(item);
result,newItem = itemDlg.run()
if (result == gtk.RESPONSE_OK):
"""The user clicked Ok, so let's save the changes back
into the gtk.ListStore"""
self.itemList.set(selection_iter
, self.cItemObject, newItem
, self.cItem, newItem.item
, self.cDescription, newItem.description
, self.cType, newItem.type
, self.cQuanity, newItem.quanity)
class itemDialog:
"""This class is used to show itemDlg"""
def __init__(self, item=None):
"""Initialize the class.
item - a Item object"""
#setup the glade file
self.gladefile = "inventory-manager.glade"
#setup the item that we will return
if (item):
#They have passed an item object
self.item = item
else:
#Just use a blank item
self.item = Item()
def run(self):
"""This function will show the itemDlg"""
#load the dialog from the glade file
self.wTree = gtk.glade.XML(self.gladefile, "itemDlg")
#Get the actual dialog widget
self.dlg = self.wTree.get_widget("itemDlg")
#Get all of the Entry Widgets and set their text
self.enItem = self.wTree.get_widget("enItem")
self.enItem.set_text(self.item.item)
"""New Code"""
self.textbuffer = gtk.TextBuffer(None)
self.enDescription = gtk.TextView()
self.enDescription.set_buffer(self.textbuffer)
self.enDescription.insert_at_cursor(self.item.description)
"""Old Code"""
"""self.enDescription = self.wTree.get_widget("enDescription")"""
"""self.enDescription.insert_at_cursor(self.item.description)"""
self.enType = self.wTree.get_widget("enType")
self.enType.set_text(self.item.type)
self.enQuanity = self.wTree.get_widget("enQuanity")
self.enQuanity.set_text(self.item.quanity)
#run the dialog and store the response
self.result = self.dlg.run()
#get the value of the entry fields
self.item.item = self.enItem.get_text()
self.item.description = self.enDescription.get_text()
self.item.type = self.enType.get_text()
self.item.quanity = self.enQuanity.get_text()
#we are done with the dialog, destory it
self.dlg.destroy()
#return the result and the item
return self.result,self.item
The section with Old Code as the title is what it was with the text area, the New Code section is what i tried after the switch, the error i get is this:
Quote:
Traceback (most recent call last):
File "pyitem.py", line 125, in on_AddItem
result,newItem = itemDlg.run()
File "pyitem.py", line 306, in run
self.enDescription.insert(0, self.item.description)
AttributeError: 'gtk.TextView' object has no attribute 'insert'