1
これは私が試しているツリービューです。リアルタイムでツリービューを更新する
def search_cr(self):
headers = {'Accept': 'application/x-bibtex; charset=utf-8'}
jsonget=(urlopen(http://api.crossref.org/works?query.author=Albert+Einstein))
data = (json.loads(jsonget.read().decode()))
# First, open a window to dispaly data
self.crrefwin = Gtk.Window()
self.crrefwin.set_title("Showing search result from CrossRef")
self.crrefwin.set_default_size(950, 350)
grid = Gtk.Grid()
self.cr_liststore = Gtk.ListStore(str, str, str, str)
self.treeview = Gtk.TreeView(model=self.cr_liststore)
for i, column_title in enumerate(["Title", "Author", "Journal", "Year"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(column_title, renderer, text=i)
self.treeview.append_column(column)
self.scrolw = Gtk.ScrolledWindow()
grid.attach(self.scrolw, 0, 0, 1, 1)
self.scrolw.add(self.treeview)
self.crrefwin.add(grid)
self.crrefwin.show_all()
#This completes `self.crrefwin`. Why it is not created here?
# Fetching data and updating to cr_liststore
for i in range(len(data["message"]["items"][0])):
url=((data["message"]["items"][i]["URL"]))
r = requests.get(url, headers=headers)
r.encoding = "utf-8"
api_tups = self.Parser.parsing_read(io.StringIO(r.text.strip()))
self.cr_liststore.append(list(api_tups[2:6]))
問題があるが、私のように、最後のi
ループの反復ごとにツリービューを追加することを期待しています:
self.cr_liststore.append(list(api_tups[2:6]))
すると、そのi
ループ内です。
実際にはは、i
ループが実行された後にのみ表示されます。
私はここで間違っていますか?