2016-08-02 107 views
1

我正在寫一個python3/GTK程序,它涉及到將包含遺傳學數據的文件添加到Gtk.ListStore中,然後使用ComboBox Entry來訪問這些數據。我已經將文件添加到列表存儲中,但是我正在努力的是如何選擇文件以及如何使用這些數據。我設置了組合框相關代碼:如何從python Gtk.ListStore中的文件中讀取數據?

self.open_sequences = Gtk.ListStore(str) 

class OsFrame(Gtk.Bin): #opens sequences for later use 
    def __init__(self, open_sequences): 

    Gtk.Bin.__init__(self) 

    self.open_sequences = open_sequences 

    self.builder = Gtk.Builder() 
    self.builder.add_from_file("openseq-page.glade") 
    self.os_box = self.builder.get_object("Open-box") 
    self.add(self.os_box) 

    self.combobox = self.builder.get_object("Open-cbox") 
    self.comboentry = self.builder.get_object("Open-cbox-entry") 
    self.filebox = self.builder.get_object("Open-file") 
    self.filebox.connect("file_set", self.on_file_selected)   
    self.comboentry.connect("activate", self.enter_callback) 

    renderer = Gtk.CellRendererText() 
    self.combobox.pack_start(renderer, True) 
    self.combobox.add_attribute(renderer, "text", 0) 
    self.combobox.set_model(open_sequences) 

def on_file_selected(self, entry): #opens a file and adds it to list store 
    file = open(self.filebox.get_filename()) 
    self.open_sequences.append([self.filebox.get_filename()]) 

def enter_callback(self, widget): #runs function when enter pressed 
    self.open_sequences.append([self.comboentry.get_text()]) #adds typed text to liststore 

回答

0

我已經解決了我的問題 - 文件名添加到liststore和使用字典來存儲數據本身。