⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treemodelfilter.py

📁 pygtk的教程
💻 PY
字号:
#!/usr/bin/env python# example treemodelfilter.pyimport pygtkpygtk.require('2.0')import gtkbugdata="""120595 NEW Custom GtkTreeModelFilter wrappers need121339 RESO dsextras.py installation directory is incorrect121611 RESO argument is guint, should be guint32121943 RESO gtk.mainiteration and gtk.mainloop defeat the caller's ex...122260 RESO Could not compile122569 NEW gtk.Window derived class segfaults122591 RESO cannot return None from CellRenderer.on_start_editing122755 RESO _wrap_gdk_window_new needs to ref return value122786 RESO don't import Numeric until it is first used123014 NEW PyGtk build problem on Win32 using the 'distutils' approach.123037 NEW gtk.ListStore.set_column_types is missing123456 RESO ItemFactory.create_items and <ImageItem> bug123458 NEED pygtk does not wrap all of gdk-pixbuf123891 NEW gobject.PARAM_CONSTRUCT problem124181 NEED Python Shell inside a gtk GUI124338 RESO Memleak when using pixbuf124593 RESO TreeModel.iter_children should accept None as parent125172 RESO gtk.TreeModelSort returns an unusable object125272 RESO error in gtk_widget_translate_coordinates wrapping125445 NEW pygtk gives no acces to PangoLayoutIter's125533 RESO set_skip_taskbar_hint and set_skip_pager_hint not wrapped126109 RESO gtk.Entry focus_out event core126323 RESO gtk_disable_setlocale cannot be used126406 RESO gtk.TreeView.expand_row() should return gboolean not None126479 RESO None iter's in custom TreeModel cause SystemException's127083 RESO Binding generation of methods which use gpointer does not...127178 RESO gtk.Widget color modify methods do not allow None for col...127504 NEW wrap GtkTreeViewColumnDropFunc128623 RESO Allow NULL as set_tip argument128988 RESO missing space in prototype confuses h2def.py129032 NEW GObject Interfaces (GInterface) support129414 RESO h2def.py doesn't see gda_log_enable()129490 RESO Provide hardware_keycode to python129754 RESO memory leak with gtk.gdk.pixmap_foreign_new()129843 NEW Make all constructors work through g_object_new()129966 RESO convert GValue containing GValueArray to PyObject131837 RESO Cannot set or get \"markup\" property from CellRendererText132040 NEW abusing setdefaultencoding()132058 RESO gtkgl bus error on constructor to gtk.gl.Area132507 RESO gtk_accel_group_connect seems to be missing132837 NEW set_from_pixmap creates a different gtk.Image than set_fr...133681 RESO memory leak in gdk.drawable.get_image134462 RESO pygtk2 segfaults134491 RESO OverflowError occurs when menu pops up.134494 RESO The Definition of argument for gtk.gdk.Pixbuf.fill should...135279 RESO codegen is using private functions135439 RESO Integrate SDL into pygtk widgets135963 RESO gc of gtk.ListStore aborts intrepeter after gtk.threads_i...136204 RESO GtkTextSearchFlags warning136205 RESO GdkPixbuf.fill passed arg changed type originating crash136297 RESO Explanatory additions to gtk.DrawingArea136597 RESO gtkgl still referenced in build files136688 RESO installation directory of pygtk 2.2136705 RESO mainquit vs. main_quit usage136707 RESO gtk.gdk.Window.raise uses reserved keyword.136731 RESO setup.py should not install the libglade DLL136811 RESO h2def ignores some functions136984 RESO Seemingly Invalid Flag for gtk.MessageDialog136989 NEW should pixbufloader throw two GErrors?137086 NEW gtk.gdk.window_lookup assertion137091 RESO \"constants\" for selection atoms137935 RESO description of gtk.gdk.atom_intern() should be in gtk.gdk...137969 NEW GenericTreeModel/TreeSelection returning GtkTreeIter inst...138104 RESO gtk_widget_style_get_property is not wrapped138163 VERI NOTA gtk.main_iteration(TRUE) unblocks every .1 seconds138476 RESO gtk.Layout is needed by gnome.canvas but is missing from ...138487 RESO PyGTK Tutorial: in Calendar sample date string is 1 day b...138576 RESO gtk.IconSet now has 2 constructors in gtk.defs, while on...138619 UNCO codegen/definitions.py could use some refactoring138772 RESO Callback parameters to input_add are incorrect138804 UNCO In gtk2.4, gdk_font_get_display and gdk_pixmap_lookup is ...138944 UNCO Cannot import gtk when pygtk installed using 'make install'139128 UNCO All constructors should be defined as constructors139130 NEW GtkEntry's constructor needs to be rewritten139312 NEED gtk.gdk.Window.get_screen method undocumented.139921 RESO Support tp_new140071 NEW Register custom widget classes.140665 RESO TypeError when creating user defined signals having third...140718 UNCO Enhance codegen with user defined type wrapper.140946 UNCO filechooser example broken141042 RESO Garbage collection causes lossage in Pango141886 UNCO Add a PyGEnum_Type142030 RESO Possible ref count error in gtk.GC142738 RESO Fatal error with multi-depth menus142997 UNCO require() breaks sys.path if libs found in /usr/local/r/local"""class TreeModelFilterExample:    # close the window and quit    def delete_event(self, widget, event, data=None):        gtk.main_quit()        return False    def __init__(self):        # Create a new window        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)        self.window.set_title("TreeModelFilter Example")        self.window.set_size_request(400, 400)        self.window.connect("delete_event", self.delete_event)        # create a liststore with one string column to use as the model        self.liststore = gtk.ListStore(int, str, str)        self.modelfilter = self.liststore.filter_new()        # create the TreeView        self.treeview = gtk.TreeView()        # create the TreeViewColumns to display the data        self.treeview.columns = [None]*3        self.treeview.columns[0] = gtk.TreeViewColumn('Bug No.')        self.treeview.columns[1] = gtk.TreeViewColumn('Status')        self.treeview.columns[2] = gtk.TreeViewColumn('Description')        # add bug data        self.states = []        for line in bugdata.split('\n'):            l = line.split()            self.liststore.append([int(l[0]), l[1], ' '.join(l[2:])])            if not l[1] in self.states:                self.states.append(l[1])        self.show_states = self.states[:]        self.modelfilter.set_visible_func(self.visible_cb, self.show_states)        self.treeview.set_model(self.modelfilter)        for n in range(3):            # add columns to treeview            self.treeview.append_column(self.treeview.columns[n])            # create a CellRenderers to render the data            self.treeview.columns[n].cell = gtk.CellRendererText()            # add the cells to the columns            self.treeview.columns[n].pack_start(self.treeview.columns[n].cell,                                                True)            # set the cell attributes to the appropriate liststore column            self.treeview.columns[n].set_attributes(                self.treeview.columns[n].cell, text=n)        # make treeview searchable        self.treeview.set_search_column(3)        # make ui layout        self.vbox = gtk.VBox()        self.scrolledwindow = gtk.ScrolledWindow()        self.bbox = gtk.HButtonBox()        self.vbox.pack_start(self.scrolledwindow)        self.vbox.pack_start(self.bbox, False)        # create toggle buttons to select filtering based on        # bug state and set buttons active        for state in self.states:            b = gtk.ToggleButton(state)            self.bbox.pack_start(b)            b.set_active(True)            b.connect('toggled', self.check_buttons)        self.scrolledwindow.add(self.treeview)        self.window.add(self.vbox)        self.window.show_all()        return    # visibility determined by state matching active toggle buttons    def visible_cb(self, model, iter, data):        return model.get_value(iter, 1) in data    # build list of bug states to show and then refilter    def check_buttons(self, tb):        del self.show_states[:]        for b in self.bbox.get_children():            if b.get_active():                self.show_states.append(b.get_label())        self.modelfilter.refilter()        returndef main():    gtk.main()if __name__ == "__main__":    tmfexample = TreeModelFilterExample()    main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -