Objectlistview filter attribute error

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Objectlistview filter attribute error

floatingshed
I've been trying to add filtering to Mike Driscoll's demo of OLV (lines 35 and 36), but getting 'ObjectListView' object has no attribute 'Filter' which I don't understand as it is built-in, any ideas? Thanks.


import wx
from ObjectListView import ObjectListView, ColumnDefn
 
########################################################################
class Book(object):
   
"""
    Model of the Book object
 
    Contains the following attributes:
    'ISBN', 'Author', 'Manufacturer', 'Title'
    """

   
#----------------------------------------------------------------------
   
def __init__(self, title, author, isbn, mfg):
       
self.isbn = isbn
       
self.author = author
       
self.mfg = mfg
       
self.title = title
 
 
########################################################################
class MainPanel(wx.Panel):
   
#----------------------------------------------------------------------
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
       
self.products = [Book("wxPython in Action", "Robin Dunn",
                             
"1932394621", "Manning"),
                         
Book("Hello World", "Warren and Carter Sande",
                             
"1933988495", "Manning")
                         
]

       
       
self.dataOlv = ObjectListView(self, wx.ID_ANY, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
       
self.setBooks()
       
        meter_flt
= self.dataOlv.Filter.TextSearch(self, columns=self.columns[4:4], text="Manning")
       
self.SetFilter(meter_flt)
 
       
# Allow the cell values to be edited when double-clicked
       
self.dataOlv.cellEditMode = ObjectListView.CELLEDIT_SINGLECLICK
 
       
# create an update button
        updateBtn
= wx.Button(self, wx.ID_ANY, "Update OLV")
        updateBtn
.Bind(wx.EVT_BUTTON, self.updateControl)
 
       
# Create some sizers
        mainSizer
= wx.BoxSizer(wx.VERTICAL)        
 
        mainSizer
.Add(self.dataOlv, 1, wx.ALL|wx.EXPAND, 5)
        mainSizer
.Add(updateBtn, 0, wx.ALL|wx.CENTER, 5)
       
self.SetSizer(mainSizer)
 
   
#----------------------------------------------------------------------
   
def updateControl(self, event):
       
"""
 
        """

       
#print "updating..."
        product_dict
= [{"title":"Core Python Programming", "author":"Wesley Chun",
                         
"isbn":"0132269937", "mfg":"Prentice Hall"},
                       
{"title":"Python Programming for the Absolute Beginner",
                         
"author":"Michael Dawson", "isbn":"1598631128",
                         
"mfg":"Course Technology"},
                       
{"title":"Learning Python", "author":"Mark Lutz",
                         
"isbn":"0596513984", "mfg":"O'Reilly"}
                       
]
        data
= self.products + product_dict
       
self.dataOlv.SetObjects(data)
 
   
#----------------------------------------------------------------------
   
def setBooks(self, data=None):
       
self.dataOlv.SetColumns([
           
ColumnDefn("Title", "left", 220, "title"),
           
ColumnDefn("Author", "left", 200, "author"),
           
ColumnDefn("ISBN", "right", 100, "isbn"),            
           
ColumnDefn("Mfg", "left", 180, "mfg")
       
])
 
       
self.dataOlv.SetObjects(self.products)
 
########################################################################
class MainFrame(wx.Frame):
   
#----------------------------------------------------------------------
   
def __init__(self):
        wx
.Frame.__init__(self, parent=None, id=wx.ID_ANY,
                          title
="ObjectListView Demo", size=(800,600))
        panel
= MainPanel(self)
 
########################################################################
class GenApp(wx.App):
 
   
#----------------------------------------------------------------------
   
def __init__(self, redirect=False, filename=None):
        wx
.App.__init__(self, redirect, filename)
 
   
#----------------------------------------------------------------------
   
def OnInit(self):
       
# create frame here
        frame
= MainFrame()
        frame
.Show()
       
return True
 
#----------------------------------------------------------------------
def main():
   
"""
    Run the demo
    """

    app
= GenApp()
    app
.MainLoop()
 
if __name__ == "__main__":
    main
()


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Objectlistview filter attribute error

Tim Roberts

> On Nov 23, 2017, at 11:53 PM, [hidden email] wrote:
>
> I've been trying to add filtering to Mike Driscoll's demo of OLV (lines 35 and 36), but getting 'ObjectListView' object has no attribute 'Filter' which I don't understand as it is built-in, any ideas?

No, the ObjectListView object does not have an attribute called Filter.  You have the source code -- you can go look it up.

Filter is a separate module in the ObjectListView package.  It gets imported into the package root, so you should be able to say:

    from ObjectListView import ObjectListView, ColumnDefn, Filter

then

    meter_flt = Filter.TextSearch( self, columns=self.columns[4:4], text="Manning" )

Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Objectlistview filter attribute error

floatingshed
In reply to this post by floatingshed
Hi Tim,

Thanks. That was the first thing I tried... but I was a thrown off by this line: meter_flt = Filter.TextSearch( self, columns=self.columns[4:4], text="Manning" ), giving the same error, which you fixed, thanks.
Now I'm getting another error with this re-jigged script: AttributeError: 'MainPanel' object has no attribute 'SetFilter'
I'm finding this a bit of a struggle!

Thanks for the help....


import wx
from ObjectListView import ObjectListView, ColumnDefn, Filter
 
########################################################################
class Book(object):
   
"""
    Model of the Book object
 
    Contains the following attributes:
    'ISBN', 'Author', 'Manufacturer', 'Title'
    """

   
#----------------------------------------------------------------------
   
def __init__(self, title, author, isbn, mfg):
       
self.isbn = isbn
       
self.author = author
       
self.mfg = mfg
       
self.title = title
 
 
########################################################################
class MainPanel(wx.Panel):
   
#----------------------------------------------------------------------
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
       
self.products = [Book("wxPython in Action", "Robin Dunn",
                             
"1932394621", "Manning"),
                         
Book("Hello World", "Warren and Carter Sande",
                             
"1933988495", "Manning")
                         
]

       
       
self.dataOlv = ObjectListView(self, wx.ID_ANY, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
       
self.setBooks()
       

       
# Allow the cell values to be edited when double-clicked
       
self.dataOlv.cellEditMode = ObjectListView.CELLEDIT_SINGLECLICK
 
       
# create an update button
        updateBtn
= wx.Button(self, wx.ID_ANY, "Update OLV")
        updateBtn
.Bind(wx.EVT_BUTTON, self.updateControl)
 
       
# Create some sizers
        mainSizer
= wx.BoxSizer(wx.VERTICAL)        
 
        mainSizer
.Add(self.dataOlv, 1, wx.ALL|wx.EXPAND, 5)
        mainSizer
.Add(updateBtn, 0, wx.ALL|wx.CENTER, 5)
       
self.SetSizer(mainSizer)
 
   
#----------------------------------------------------------------------
   
def updateControl(self, event):
       
"""
 
        """

       
#print "updating..."
        product_dict
= [{"title":"Core Python Programming", "author":"Wesley Chun",
                         
"isbn":"0132269937", "mfg":"Prentice Hall"},
                       
{"title":"Python Programming for the Absolute Beginner",
                         
"author":"Michael Dawson", "isbn":"1598631128",
                         
"mfg":"Course Technology"},
                       
{"title":"Learning Python", "author":"Mark Lutz",
                         
"isbn":"0596513984", "mfg":"O'Reilly"}
                       
]
        data
= self.products + product_dict
       
self.dataOlv.SetObjects(data)
 
   
#----------------------------------------------------------------------
   
def setBooks(self, data=None):
       
self.columns = [
           
ColumnDefn("Title", "left", 220, "title"),
           
ColumnDefn("Author", "left", 200, "author"),
           
ColumnDefn("ISBN", "right", 100, "isbn"),            
           
ColumnDefn("Mfg", "left", 180, "mfg")
       
]
 
       
self.dataOlv.SetColumns(self.columns)
       
self.dataOlv.SetObjects(self.products)
       
       
        meter_flt
= Filter.TextSearch( self, columns=self.columns[4:4], text="Manning" )
       
self.SetFilter(meter_flt)
       
 
########################################################################
class MainFrame(wx.Frame):
   
#----------------------------------------------------------------------
   
def __init__(self):
        wx
.Frame.__init__(self, parent=None, id=wx.ID_ANY,
                          title
="ObjectListView Demo", size=(800,600))
        panel
= MainPanel(self)
 
########################################################################
class GenApp(wx.App):
 
   
#----------------------------------------------------------------------
   
def __init__(self, redirect=False, filename=None):
        wx
.App.__init__(self, redirect, filename)
 
   
#----------------------------------------------------------------------
   
def OnInit(self):
       
# create frame here
        frame
= MainFrame()
        frame
.Show()
       
return True
 
#----------------------------------------------------------------------
def main():
   
"""
    Run the demo
    """

    app
= GenApp()
    app
.MainLoop()
 
if __name__ == "__main__":
    main
()




On Friday, November 24, 2017 at 7:53:27 AM UTC, [hidden email] wrote:
I've been trying to add filtering to Mike Driscoll's demo of OLV (lines 35 and 36), but getting 'ObjectListView' object has no attribute 'Filter' which I don't understand as it is built-in, any ideas? Thanks.


import wx
from ObjectListView import ObjectListView, ColumnDefn
 
########################################################################
class Book(object):
   
"""
    Model of the Book object
 
    Contains the following attributes:
    'ISBN', 'Author', 'Manufacturer', 'Title'
    """

   
#----------------------------------------------------------------------
   
def __init__(self, title, author, isbn, mfg):
       
self.isbn = isbn
       
self.author = author
       
self.mfg = mfg
       
self.title = title
 
 
########################################################################
class MainPanel(wx.Panel):
   
#----------------------------------------------------------------------
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
       
self.products = [Book("wxPython in Action", "Robin Dunn",
                             
"1932394621", "Manning"),
                         
Book("Hello World", "Warren and Carter Sande",
                             
"1933988495", "Manning")
                         
]

       
       
self.dataOlv = ObjectListView(self, wx.ID_ANY, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
       
self.setBooks()
       
        meter_flt
= self.dataOlv.Filter.TextSearch(self, columns=self.columns[4:4], text="Manning")
       
self.SetFilter(meter_flt)
 
       
# Allow the cell values to be edited when double-clicked
       
self.dataOlv.cellEditMode = ObjectListView.CELLEDIT_SINGLECLICK
 
       
# create an update button
        updateBtn
= wx.Button(self, wx.ID_ANY, "Update OLV")
        updateBtn
.Bind(wx.EVT_BUTTON, self.updateControl)
 
       
# Create some sizers
        mainSizer
= wx.BoxSizer(wx.VERTICAL)        
 
        mainSizer
.Add(self.dataOlv, 1, wx.ALL|wx.EXPAND, 5)
        mainSizer
.Add(updateBtn, 0, wx.ALL|wx.CENTER, 5)
       
self.SetSizer(mainSizer)
 
   
#----------------------------------------------------------------------
   
def updateControl(self, event):
       
"""
 
        """

       
#print "updating..."
        product_dict
= [{"title":"Core Python Programming", "author":"Wesley Chun",
                         
"isbn":"0132269937", "mfg":"Prentice Hall"},
                       
{"title":"Python Programming for the Absolute Beginner",
                         
"author":"Michael Dawson", "isbn":"1598631128",
                         
"mfg":"Course Technology"},
                       
{"title":"Learning Python", "author":"Mark Lutz",
                         
"isbn":"0596513984", "mfg":"O'Reilly"}
                       
]
        data
= self.products + product_dict
       
self.dataOlv.SetObjects(data)
 
   
#----------------------------------------------------------------------
   
def setBooks(self, data=None):
       
self.dataOlv.SetColumns([
           
ColumnDefn("Title", "left", 220, "title"),
           
ColumnDefn("Author", "left", 200, "author"),
           
ColumnDefn("ISBN", "right", 100, "isbn"),            
           
ColumnDefn("Mfg", "left", 180, "mfg")
       
])
 
       
self.dataOlv.SetObjects(self.products)
 
########################################################################
class MainFrame(wx.Frame):
   
#----------------------------------------------------------------------
   
def __init__(self):
        wx
.Frame.__init__(self, parent=None, id=wx.ID_ANY,
                          title
="ObjectListView Demo", size=(800,600))
        panel
= MainPanel(self)
 
########################################################################
class GenApp(wx.App):
 
   
#----------------------------------------------------------------------
   
def __init__(self, redirect=False, filename=None):
        wx
.App.__init__(self, redirect, filename)
 
   
#----------------------------------------------------------------------
   
def OnInit(self):
       
# create frame here
        frame
= MainFrame()
        frame
.Show()
       
return True
 
#----------------------------------------------------------------------
def main():
   
"""
    Run the demo
    """

    app
= GenApp()
    app
.MainLoop()
 
if __name__ == "__main__":
    main
()


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Objectlistview filter attribute error

floatingshed
In reply to this post by floatingshed
Hi Tim, figured it out by myself! Thanks for your time.


On Friday, November 24, 2017 at 7:53:27 AM UTC, [hidden email] wrote:
I've been trying to add filtering to Mike Driscoll's demo of OLV (lines 35 and 36), but getting 'ObjectListView' object has no attribute 'Filter' which I don't understand as it is built-in, any ideas? Thanks.


import wx
from ObjectListView import ObjectListView, ColumnDefn
 
########################################################################
class Book(object):
   
"""
    Model of the Book object
 
    Contains the following attributes:
    'ISBN', 'Author', 'Manufacturer', 'Title'
    """

   
#----------------------------------------------------------------------
   
def __init__(self, title, author, isbn, mfg):
       
self.isbn = isbn
       
self.author = author
       
self.mfg = mfg
       
self.title = title
 
 
########################################################################
class MainPanel(wx.Panel):
   
#----------------------------------------------------------------------
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
       
self.products = [Book("wxPython in Action", "Robin Dunn",
                             
"1932394621", "Manning"),
                         
Book("Hello World", "Warren and Carter Sande",
                             
"1933988495", "Manning")
                         
]

       
       
self.dataOlv = ObjectListView(self, wx.ID_ANY, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
       
self.setBooks()
       
        meter_flt
= self.dataOlv.Filter.TextSearch(self, columns=self.columns[4:4], text="Manning")
       
self.SetFilter(meter_flt)
 
       
# Allow the cell values to be edited when double-clicked
       
self.dataOlv.cellEditMode = ObjectListView.CELLEDIT_SINGLECLICK
 
       
# create an update button
        updateBtn
= wx.Button(self, wx.ID_ANY, "Update OLV")
        updateBtn
.Bind(wx.EVT_BUTTON, self.updateControl)
 
       
# Create some sizers
        mainSizer
= wx.BoxSizer(wx.VERTICAL)        
 
        mainSizer
.Add(self.dataOlv, 1, wx.ALL|wx.EXPAND, 5)
        mainSizer
.Add(updateBtn, 0, wx.ALL|wx.CENTER, 5)
       
self.SetSizer(mainSizer)
 
   
#----------------------------------------------------------------------
   
def updateControl(self, event):
       
"""
 
        """

       
#print "updating..."
        product_dict
= [{"title":"Core Python Programming", "author":"Wesley Chun",
                         
"isbn":"0132269937", "mfg":"Prentice Hall"},
                       
{"title":"Python Programming for the Absolute Beginner",
                         
"author":"Michael Dawson", "isbn":"1598631128",
                         
"mfg":"Course Technology"},
                       
{"title":"Learning Python", "author":"Mark Lutz",
                         
"isbn":"0596513984", "mfg":"O'Reilly"}
                       
]
        data
= self.products + product_dict
       
self.dataOlv.SetObjects(data)
 
   
#----------------------------------------------------------------------
   
def setBooks(self, data=None):
       
self.dataOlv.SetColumns([
           
ColumnDefn("Title", "left", 220, "title"),
           
ColumnDefn("Author", "left", 200, "author"),
           
ColumnDefn("ISBN", "right", 100, "isbn"),            
           
ColumnDefn("Mfg", "left", 180, "mfg")
       
])
 
       
self.dataOlv.SetObjects(self.products)
 
########################################################################
class MainFrame(wx.Frame):
   
#----------------------------------------------------------------------
   
def __init__(self):
        wx
.Frame.__init__(self, parent=None, id=wx.ID_ANY,
                          title
="ObjectListView Demo", size=(800,600))
        panel
= MainPanel(self)
 
########################################################################
class GenApp(wx.App):
 
   
#----------------------------------------------------------------------
   
def __init__(self, redirect=False, filename=None):
        wx
.App.__init__(self, redirect, filename)
 
   
#----------------------------------------------------------------------
   
def OnInit(self):
       
# create frame here
        frame
= MainFrame()
        frame
.Show()
       
return True
 
#----------------------------------------------------------------------
def main():
   
"""
    Run the demo
    """

    app
= GenApp()
    app
.MainLoop()
 
if __name__ == "__main__":
    main
()


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.