Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Objectlistview Python:筛选

Objectlistview Python:筛选
EN

Stack Overflow用户
提问于 2015-08-05 09:29:46
回答 1查看 1.4K关注 0票数 2

我试图根据数据中某一列中的文本值筛选对象列表视图。我想不出如何正确地构造过滤器。我指的是:

http://objectlistview.sourceforge.net/python/features.html http://objectlistview.sourceforge.net/python/majorClasses.html

我能够让Filter.Head(n)成功地工作,但不能让Filter.TextSearch(objectListView、columns=()、text="")工作,因为我不知道参数类型是什么。

我编写了以下代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
def OnFilterMeter(self,event):
    list = self.exception_panel.col_list   ## The lenght of my column list
    col  = list[len(list)-1]     ## I want to search the last column 
    meter_flt = Filter.TextSearch(self.exception_panel,columns = (col), text = "10") ## Create filter to find string 10 in last column
    self.exception_panel.SetFilter(meter_flt)
    self.exception_panel.populate()

我不明白为什么这不管用。当程序试图再次填充列表视图时,它不会过滤列表。至少,它应该显示所有空白,因为它找不到任何等于"10“的项目。请帮帮忙。谢谢

下面是我的代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class Display_Manager(wx.Frame):
def __init__(self, parent, id, title):
    wx.Frame.__init__(self, parent, -1, title)          
    self.exception_panel =  Exception_Display(self,0)
    # self.exception_panel2 = Exception_Display(self,1)
    ## Setup FileMenu Bar Setup
    filemenu= wx.Menu()                                                                             ## Create Menu Bar
    filemenu.Append(ID_LOG,"Login","Login as user with password.")                                  ## Clicking shoudl load a single dailyi report which user selects
    filemenu.Append(ID_LOAD,"Load Report","Load Daliy Exception Report")                            ## Clicking shoudl load a single dailyi report which user selects
    filemenu.Append(ID_LOADS,"Load All","Load All Daliy Exception Reports")                         ## Clicking should load all daily reports in a directory which user selects
    filemenu.Append(ID_REFRESH,"Refresh DB","Refresh Database. Overwrites any un saved data.")      ## Clicking should refreseh the database and overwrite any unsaved changes
    filemenu.Append(ID_SAVE,"Save DB","Saves and commits any changes to database.")                 ## Clicking will save and commit any changes or new data to the database
    filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")                                       ## exit the program
    ## Setup Edit Menu Bar
    editmenu = wx.Menu()
    editmenu.Append(ID_ADD,"Add","Add Exception")
    editmenu.Append(ID_DELETE,"Delete","Delete Exception")
    editmenu.Append(ID_UNDO,"Stepback DB","Go back to a previous version of the database")
    editmenu.Append(ID_REDO,"Stepfoward DB","Go foward to a previous version of the database")
    ## Setup Report Menu
    reportmenu = wx.Menu()
    reportmenu.Append(ID_REPORT,"Exception Report","Generate an Excel Report of selected exceptions.")
    reportmenu.Append(ID_REPORT2,"Meter Report","Generate an Excel Report of selected exceptions.")
    reportmenu.Append(ID_REPORT3,"Transformer Report","Generate an Excel Report of selected exceptions.")
    ## Setup Bucket Menu
    bucketmenu = wx.Menu()
    bucketmenu.Append(ID_METERPROB,"Meter Problem","Place the meter in the meter problem bucket.")
    bucketmenu.Append(ID_LOWVOLT,"Investigate Low Voltage","Place the meter in the investigate bucket.")
    bucketmenu.Append(ID_TURNS,"Turns Ratio","Place the meter in the turns ratio bucket.")
    ## Setup Configure Menu Menu
    configmenu = wx.Menu()
    configmenu.Append(ID_FILTER,"Set Filters","Filter by district and company.")
    configmenu.Append(ID_SAVEFIL,"Save Filters","Save Filters for Later use.")
    configmenu.Append(ID_LOADFIL,"Load Filters","Load Filters for Later use.")

    ## Add file menu bar
    menuBar = wx.MenuBar()
    menuBar.Append(filemenu,"&File")
    menuBar.Append(editmenu, "&Edit")
    menuBar.Append(reportmenu, "&Reports")
    menuBar.Append(configmenu, "&Config")
    menuBar.Append(bucketmenu, "&Bucket")
    self.SetMenuBar(menuBar)

    ## Create Toolbar
    tb = self.CreateToolBar( wx.TB_HORIZONTAL | wx.NO_BORDER | 
    wx.TB_FLAT | wx.TB_TEXT)
    tb.AddSimpleTool(10, wx.Bitmap('images/database.png'), 'Save Database')
    tb.AddSimpleTool(20, wx.Bitmap('images/excel.png'), 'Get Quick Excel Report')
    tb.AddSimpleTool(70, wx.Bitmap('images/analyze.png'), 'Analyze Selected Exceptions')
    tb.AddSimpleTool(71, wx.Bitmap('images/refresh.png'), 'Refresh Selected Relationships')
    tb.AddSeparator()
    tb.AddSimpleTool(30, wx.Bitmap('images/today.png'), 'Filter only the latest data.')
    tb.AddSimpleTool(40, wx.Bitmap('images/all_time.png'), 'Filter All Data from all time')
    tb.AddSimpleTool(41, wx.Bitmap('images/date_range.png'), 'Select a date range to view data over')
    tb.AddSeparator()
    tb.AddSimpleTool(50, wx.Bitmap('images/AMI_Meter.png'), 'Bucket as meter problem')
    tb.AddSimpleTool(60, wx.Bitmap('images/violation.png'), 'Bucket to District')
    tb.AddSimpleTool(61, wx.Bitmap('images/turns.png'), 'Bucket Turns Ratio')
    tb.AddSimpleTool(62, wx.Bitmap('images/plan.png'), 'Bucket for further review for planning engineer')
    tb.AddSeparator()
    tb.AddSimpleTool(63, wx.Bitmap('images/cyme.png'), 'Load CYME model for specific meter')
    tb.AddSimpleTool(64, wx.Bitmap('images/relate_dot.png'), 'Cluster & Relate Meter Exceptions')
    tb.AddSeparator()
    tb.AddSimpleTool(65, wx.Bitmap('images/bucket_m.png'), 'Filter Meter Bucket')
    tb.AddSimpleTool(66, wx.Bitmap('images/bucket_v.png'), 'Filter Violation Bucket')
    tb.AddSimpleTool(67, wx.Bitmap('images/bucket_t.png'), 'Filter Turns Ratio Bucket')
    tb.AddSimpleTool(68, wx.Bitmap('images/bucket_p.png'), 'Filter Planning Bucket')
    tb.SetToolBitmapSize((84,84))
    tb.Realize()




    self.Bind(wx.EVT_TOOL,self.OnRefresh,id =71)
    self.Bind(wx.EVT_TOOL,self.OnAnalyze,id =70)
    self.Bind(wx.EVT_TOOL,self.OnSave,id =10)

    self.Bind(wx.EVT_TOOL,self.OnBucketMeter,id =50)
    self.Bind(wx.EVT_TOOL,self.OnVioMeter,id =60)
    self.Bind(wx.EVT_TOOL,self.OnTurnsMeter,id =61)
    self.Bind(wx.EVT_TOOL,self.OnPlanMeter,id =62)

    self.Bind(wx.EVT_TOOL,self.OnFilterMeter,id =65)
    # self.Bind(wx.EVT_TOOL,self.OnFilterMeter,id =66)
    # self.Bind(wx.EVT_TOOL,self.OnFilterMeter,id =67)
    # self.Bind(wx.EVT_TOOL,self.OnFilterMeter,id =68)

    ## Create Sizers
    # self.main_sizer = wx.BoxSizer(wx.VERTICAL)
    # self.top_sizer = wx.BoxSizer(wx.HORIZONTAL)
    # self.bottom_sizer = wx.BoxSizer(wx.HORIZONTAL)
    # self.main_sizer.Add(self.top_sizer,0,wx.EXPAND)
    # self.main_sizer.Add(self.bottom_sizer,0,wx.EXPAND)

    ## Show the frame
    # self.SetSizer(self.main_sizer)

    self.Center()
    self.Show(True)


def OnSave(self,event):
    session.commit()
    print "ON Save"
def OnRefresh(self,event): 
    self.exception_panel.populate()
    self.ColorBuckets()
    print "OnRelate"
def OnAnalyze(self,event): 
    objectList = self.exception_panel.GetSelectedObjects()          ## Get list of selected objects to relate in the database
    for object in objectList:
        print object
        object.calculate()
    # print self.GetValueAt(self.GetObjectAt(event.rowIndex),event.subItemIndex)
    # self.temp_value = event.editor.GetValue()
    self.exception_panel.populate()
    print "OnAnalze"
def OnFilterDate1(self,event):
    print "on Filter date"
def OnFilterDate2(self,event):
    print "on Filter date"
def OnFilterDate3(self,event):
    print "on Filter date"

def OnFilterMeter(self,event):
    list = self.exception_panel.col_list
    col  = list[len(list)-1]
    # meter_flt = Filter.Head(10)
    meter_flt = Filter.TextSearch(self.exception_panel,columns = (col), text = "10")
    self.exception_panel.SetFilter(meter_flt)
    self.exception_panel.populate()
    # self.exception_panel.Refresh()


    # self.exception_panel.populate()

    # self.exception_panel.SetObjects(qrty_meters_excpt)
    # self.exception_panel.populate()

    print "On Filter Meter"

def OnBucketMeter(self,event):
    objectList = self.exception_panel.GetSelectedObjects()
    for object in objectList:
        print object
        object.known_flags = 20         ## Meter Mismatch Flag Known ***ffa500
    self.exception_panel.populate()
    self.ColorBuckets()
def OnVioMeter(self,event):
    objectList = self.exception_panel.GetSelectedObjects()
    for object in objectList:
        object.known_flags = 10         ## Meter Mismatch Flag Known ***ffa500
    self.exception_panel.populate()
    self.ColorBuckets() 
def OnTurnsMeter(self,event):
    objectList = self.exception_panel.GetSelectedObjects()
    for object in objectList:
        object.known_flags = 30         ## Meter Mismatch Flag Known ***ffa500
    self.exception_panel.populate()
    self.ColorBuckets()
def OnPlanMeter(self,event):
    objectList = self.exception_panel.GetSelectedObjects()
    for object in objectList:
        object.known_flags = 40         ## Meter Mismatch Flag Known ***ffa500
    self.exception_panel.populate()
    self.ColorBuckets() 

def ColorBuckets(self):         ## Color All Buckets according to knowflags
    ## Query the session for only items that have know_flags greate than 0
    qrty_color_buckets = session.query(Exception).filter(Exception.known_flags != "").all()
    print qrty_color_buckets
    for exception in qrty_color_buckets:
        print exception.known_flags == 10
        flag = int(exception.known_flags)       ## alias the flag
        if flag == 20:      ## Meter Mismatch
            self.exception_panel.SetItemBackgroundColour(self.exception_panel.GetIndexOf(exception),'#ffa500')      ## Oranage
        elif flag == 10:        ## Violation
            self.exception_panel.SetItemBackgroundColour(self.exception_panel.GetIndexOf(exception),'#ff0000')      ## Red
        elif flag == 30:        ## Turns Ratio
            self.exception_panel.SetItemBackgroundColour(self.exception_panel.GetIndexOf(exception),'#0066CC')      ## Blue
        elif flag == 40:    ## Plan referal
            self.exception_panel.SetItemBackgroundColour(self.exception_panel.GetIndexOf(exception),'#FFFF00')      ## Yellow

请看函数OnFilterMeter。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-07 03:01:23

下面对我有用,它对第二列进行搜索,它只显示一个匹配的条目。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# -*- coding: utf-8 -*-
import datetime
import wx
import wx.lib.sized_controls as SC
import ObjectListView as OLV

class MyData:
    def __init__(self, year, month, day, level, sets, reps):
        self.date = datetime.date(year, month, day)
        self.level = level
        self.sets = sets
        self.reps = reps

    def GetDate(self):
        return self.date

    def GetLevel(self):
        return self.level

    def GetSets(self):
        return self.sets

    def GetRepetitions(self):
        return self.reps


class MyListCtrl(OLV.GroupListView):
    def __init__(self, parent):
        super(MyListCtrl, self).__init__(parent, wx.ID_ANY, style=wx.LC_REPORT)
        self.SetColumns(self._ColumnDefinitions())
        meter_flt = OLV.Filter.TextSearch(self, columns=self.columns[2:3],
                                          text="7")
        self.SetFilter(meter_flt)
        self.SetObjects(self._DataObjects())

    def _DataObjects(self):
        return [MyData(2010,10,8, 1, 2, 3),
                MyData(2005,10,10, 7, 2, 3),
                MyData(2010,10,3, 2, 2, 3),
                MyData(2012,10,10, 1, 2, 3),
                MyData(2014,10,10, 1, 2, 3)
                ]

    def _ColumnDefinitions(self):
        return [OLV.ColumnDefn('Date', valueGetter='GetDate', groupKeyGetter='GetDate'),
                OLV.ColumnDefn('Level', valueGetter='GetLevel', width=150),
                OLV.ColumnDefn('Sets', valueGetter='GetSets', width=100, groupKeyGetter='GetSets'),
                OLV.ColumnDefn('Reps', valueGetter='GetRepetitions', width=200)]


class MyFrame(SC.SizedFrame):
    def __init__(self):
        super(MyFrame, self).__init__(None)
        pane = self.GetContentsPane()

        olv = MyListCtrl(pane)
        olv.SetSizerProps(expand=True, proportion=1)


if __name__ == '__main__':
    import wx.lib.mixins.inspection as WIT
    app = WIT.InspectableApp()
    win = MyFrame()
    win.Show()
    app.MainLoop()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31839115

复制
相关文章
mysql中group_concat长度限制的问题
在mysql中的group_concat函数默认支持的最大字符数为1024。 当你使用group_concat函数时,超出第1024字符的字符会全部丢失。
botkenni
2023/10/09
2.6K0
GROUP BY 后 SELECT 列的限制:which is not functionally dependent on columns in GROUP BY clause
标准 SQL 规定,在对表进行聚合查询的时候,只能在 SELECT 子句中写下面 3 种内容:通过 GROUP BY 子句指定的聚合键、聚合函数(SUM 、AVG 等)、常量。我们来看个例子
chenchenchen
2021/09/06
3.2K0
【BUG之group_concat默认长度限制】
问题:mysql数据库使用group_concat将多个id组成字符串数组,一共200个,到160个被截断;
用户5640963
2019/07/25
3.1K0
资源限制问题
ulimit 是一个 shell 内置命令,用于设置当前 shell 会话的资源限制。
是山河呀
2025/02/03
950
MySQL group by数据丢失问题
在使用group by时需要注意,group by 关键字后的该列一定是唯一的,如果group列出现数据重复数据时,仅会显示一条数据。
关忆北.
2022/05/05
2.5K0
MySQL group by数据丢失问题
MySQL中group by 与 order by 一起使用排序问题
没有得到我们需要的结果,这是因为group by 和 order by 一起使用时,会先使用group by 分组,并取出分组后的第一条数据,所以后面的order by 排序时根据取出来的第一条数据来排序的,但是第一条数据不一定是分组里面的最大数据。
星哥玩云
2022/08/18
1.8K0
MySQL中group by 与 order by 一起使用排序问题
MySQL里面的group by问题浅析
mysql> select backup_date ,count(*) piece_no from redis_backup_result;
jeanron100
2018/09/29
8410
GROUP BY与COUNT用法详解
在介绍GROUP BY 和 HAVING 子句前,我们必需先讲讲sql语言中一种特殊的函数:聚合函数, 例如SUM, COUNT, MAX, AVG等。这些函数和其它函数的根本区别就是它们一般作用在多条记录上。
全栈程序员站长
2022/08/24
2.7K0
GROUP BY与COUNT用法详解
count(distinct) 与group by 浅析
项目github地址:bitcarmanlee easy-algorithm-interview-and-practice 欢迎大家star,留言,一起学习进步
全栈程序员站长
2022/08/26
9210
gitlab访问限制问题------Forbidden
重启-gitlab:       gitlab-ctl restart          
Wyc
2018/09/11
2.5K0
Group_concat介绍与例子
进公司做的第一个项目就是做一个订单追踪查询,里里外外连接了十一个表,作为公司菜鸡的我麻了爪.
全栈程序员站长
2022/07/07
2620
Group_concat介绍与例子
group by 报错_group by null
mysql bug #8652 有可能不成功,依赖于生成的两次虚拟表的主键不同引发报错
全栈程序员站长
2022/11/11
1.3K0
group by 报错_group by null
组复制要求和限制 | 全方位认识 MySQL 8.0 Group Replication
--upgrade=minimal:当MySQL Server指定--upgrade=minimal选项启动时,如果发现需要执行更新,则,在执行升级操作完成之后,可能会导致组复制无法启动,因为minimal选项在执行更新时,只会更新数据字典、information_schema、performance_schema,但不会更新组复制内部所依赖的系统表(--upgrade选项在MySQL 8.0.16版本引入,之后,升级操作将不再需要单独使用mysql_upgrade工具,默认情况下--upgrade选项值为AUTO,表示自动判断是否需要执行完整的更新操作)。
老叶茶馆
2020/11/11
1.1K0
组复制要求和限制 | 全方位认识 MySQL 8.0 Group Replication
Socket代理神器客户端Proxifier+服务端ss5
在日常工作中我们经常会使用到代理, 这里记录一下Proxifier和ss5的使用,这两个工具既可以单独使用,也可以配合使用。本文讲解proxifier+ss5配合使用的场景及配置。
冯大仙
2021/11/12
2.8K0
MySQL5.7之group by语法问题
使用group by 进行分组查询时,提示异常: SELECT list is not in GROUP BY clause and contains nonaggregated column ‘XXX’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode =only_full_group_by
执笔记忆的空白
2020/12/24
8710
only_full_group_by问题而引发的对group by的深入思考
最近在项目中使用mysql的group by进行分组查询的场景比较多,其中一次遇到了一个问题,即在开发环境执行一个如下sql时是正确且可执行的,
翎野君
2023/05/12
2700
only_full_group_by问题而引发的对group by的深入思考
[MySQL] 测试where group by order by的索引问题
1. select * from test where a=xx group by b order by c 如何加索引
唯一Chat
2019/09/10
1.4K0
[MySQL] 测试where group by order by的索引问题
搭建使用Socks Server 5 服务器
收到一个这样的需求:要求访问腾讯的一个服务,无论身在哪里,都必须通过制定 ip 访问此服务,因为公司之前的 V** 是我搭的,领导找我做这个需求,但是 V** 此事并没有能适配此需求,因为我的那个 V** 只是针对内网服务才走 V** 流量,而腾讯的相关服务需要走外网流量,而且出口 ip 这个时候需要被代理成指定 ip。所以此文章针对次任务做个记录。
cuijianzhe
2022/06/14
1.5K0
搭建使用Socks Server 5 服务器
MySQL索引优化order by与group by
MySQL索引优化order by与group by 案例一 name符合最左前缀法则,但在age处断了,所以只能用到name列,索引长度202,order by也用到了index_union索引 树,通过Extra可看出。 案例二 where后符合最左前缀,所以只用到了name列,而order by处不是用的索引树index_union,因为age还没排序呢, position排序肯定是乱的,需要将结果集放在内存中排序。 案例三 如第二张图所示,在确定最左列name后,其实下面
晓果冻
2022/09/08
6140
MySQL索引优化order by与group by
group by 与 where, having以及顺序
1. GROUP BY子句必须出现在WHERE子句之后,ORDER BY子句之前. HAVING语句必须在ORDER BY子句之后。(where先执行,再groupby分组;groupby先分组,having在执行。)
全栈程序员站长
2022/09/01
2.8K0
group by 与 where, having以及顺序

相似问题

在nodejs中使用导入,通常使用require

32

无法在模块之外使用导入语句- im试图在我的nodejs服务器中声明导入,但我不能

12

如何使用nodejs导入别名

16

在NodeJS中同时导入多个模块

20

使用NodeJs在Aerospike中进行批量导入

221
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文