简体   繁体   English

Glade,Python,GTK3:数据列表视图

[英]Glade, python, GTK3: list view for data

After some frustrating hours doing something I expect to be simple (it was, in GTK-2) hereby my question. 经过一些令人沮丧的工作之后,我希望这很简单(在GTK-2中是这样)。 Sorry for lack of code or specifics in this question, as I have NOTHING at all working. 很抱歉,这个问题缺少代码或细节,因为我什么都没做。

I'm writing an application that pulls some data from a database and has to present it in a table form. 我正在编写一个应用程序,该应用程序从数据库中提取一些数据,并且必须以表格形式显示。 Standard stuff, I'd say. 我会说标准的东西。 I just can't figure out how to do it. 我只是不知道该怎么做。 No tutorials (and those that are there, don't work for me, as I have more than just a ListStore in my window). 没有教程(那里的教程对我不起作用,因为我的窗口中不仅有ListStore)。 I'm designing my UI in Glade, it's got a notebook with a grid in it with various stuff, including a place where the list should come. 我在Glade中设计我的UI,它有一个笔记本,上面有网格,上面有各种各样的东西,包括应该出现列表的地方。

I've tried adding a ListStore object, but can't get it to display at all. 我尝试添加一个ListStore对象,但是根本无法显示它。 Python 2.7.6, Glade 3.16.1. Python 2.7.6,Glade 3.16.1。

    self.liststore = self.builder.get_object('liststore1')
    self.liststore.append(['1st column','2nd column'])

This is supposed to show the data, it doesn't. 这应该显示数据,但不显示。 I can't get the ListStore thing in Glade to show up as preview, can only add it as toplevel object and not where it's supposed to go. 我无法在Glade中获得ListStore东西来显示为预览,只能将其添加为顶级对象,而不能将其添加到预期位置。

This is a very basic example that only shows one column with two entries. 这是一个非常基本的示例,仅显示具有两个条目的一列。 One of them created in the glade file, the other one created with python so you can see how to modify the liststore: 其中一个是在glade文件中创建的,另一个是使用python创建的,因此您可以看到如何修改列表存储:

The glade file: 林间空地文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
  <requires lib="gtk+" version="3.10"/>
  <object class="GtkListStore" id="liststore1">
    <columns>
      <!-- column-name test -->
      <column type="gchararray"/>
    </columns>
    <data>
      <row>
        <col id="0" translatable="yes">entry</col>
      </row>
    </data>
  </object>
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <property name="default_width">247</property>
    <property name="default_height">188</property>
    <child>
      <object class="GtkTreeView" id="treeview1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="model">liststore1</property>
        <child internal-child="selection">
          <object class="GtkTreeSelection" id="treeview-selection1"/>
        </child>
        <child>
          <object class="GtkTreeViewColumn" id="treeviewcolumn1">
            <property name="title" translatable="yes">test-column</property>
            <child>
              <object class="GtkCellRendererText" id="cellrenderertext1"/>
              <attributes>
                <attribute name="text">0</attribute>
              </attributes>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

And this is the python file: 这是python文件:

from gi.repository import Gtk

class Test:
    def __init__(self):
        builder = Gtk.Builder()
        builder.add_from_file('test.glade')

        self.liststore = builder.get_object('liststore1')
        #append something with python:
        self.liststore.append(('stackoverflow',))

        window = builder.get_object('window1')
        window.connect('delete-event', Gtk.main_quit)
        window.show_all()

if __name__ == '__main__':
    Test()
    Gtk.main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM