【发布时间】:2015-05-31 01:05:40
【问题描述】:
使用:python 2.79,gtk 2.0
亲爱的 python 和 PyGtk 用户
在我的程序中,我希望有机会使用代码中的方法在 gtk.TreeView 中显示一个大数据文件的搜索结果。在创建 ListStore 的函数中,我还创建了商店正在使用的 csv 文件。现在我可以看到,在使用不同的关键字进行新搜索后,csv 文件发生了变化,但 TreeView 没有,它仍然保留第一次搜索的结果,尽管每次 self.search 运行时我都会清除存储。如果每次新搜索都需要重新启动程序,这真的很令人不安......
我已经尝试了一些东西,比如为商店的数据创建一个适当的函数,但没有任何作用,事实上我没有很多想法......
我在互联网上找到的所有关于此的内容都是关于使用计时器或其他更深刻的主题自动刷新商店,似乎每个人都知道如何做到这一点,而不是我......
谁能告诉我,我犯了什么错误?如何刷新 TreeView?(如您所见,self.search 由按钮调用...)这里是代码的相关部分:
import gtk, csv
class BASE:
#...
#some other funtions, irrelevant for the problem
#...
def search(self, widget, event, data=None):
#...
#all the searchingstuff and the creation of 'inwrite.csv'
#...
with open('/home/emil/Documents/inwrite.csv', 'r') as storefile:
lines = storefile.readlines()
store = gtk.ListStore(str, str, str, str, str, str)
store.clear()
i=0
while i < len(lines):
line = [lines[i]]
csvfile = csv.reader(line, delimiter=',')
for row in csvfile:
temp = (row[0], row[1], row[2], row[3], row[4], row[5])
store.append(temp)
i = i + 1
self.tabview = gtk.TreeView(store)
self.tabview.set_rules_hint(True)
self.tabview.set_reorderable(True)
self.sw.add(self.tabview)
self.tabview.show()
self.create_columns(self.tabview)
def __init__(self):
#...
#creating the Window, entries,...
#...
self.button1 = gtk.Button('Buscar')
self.button1.connect('clicked', self.search, 'button 1')
#...
#packing and showing the whole GUI
#...
def create_columns(self, tabview):
rendererText = gtk.CellRendererText()
rendererText.props.wrap_width = 80
rendererText.props.wrap_mode = gtk.WRAP_WORD
column = gtk.TreeViewColumn('Codigo', rendererText, text=0)
column.set_sort_column_id(0)
self.tabview.append_column(column)
#...
#creating 5 more columns by the same principle
#...
def main(self):
gtk.main()
if __name__=='__main__':
base = BASE()
run = base
run.main()
感谢您的帮助,如果您需要更多信息,请告诉我!
【问题讨论】:
标签: python treeview gtk store pygtk