aboutsummaryrefslogtreecommitdiffstats
path: root/misc/gui/wxbe
blob: e71ae0c962fc43290ef5311fbb6e950bceae79d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
import wx
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
import sys, os.path
from libbe import bugdir, names
from libbe.bug import cmp_status, cmp_severity, cmp_time, cmp_full

class MyApp(wx.App):
    def OnInit(self):
        frame = BugListFrame(None, title="Bug List")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

class BugListFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        bugs = BugList(self)

        # Widgets to display/sort/edit will go in this panel
        # for now it is just a placeholder
        panel = wx.Panel(self)
        panel.SetBackgroundColour("RED")

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(panel, 0, wx.EXPAND)
        vbox.Add(bugs, 1, wx.EXPAND)
        
        self.SetAutoLayout(True)
        self.SetSizer(vbox)
        self.Layout()

class BugList(wx.ListCtrl, ListCtrlAutoWidthMixin):
    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent,
                             style=wx.LC_REPORT)
        ListCtrlAutoWidthMixin.__init__(self)

        self.bugdir = bugdir.tree_root(".")
        self.buglist = list(self.bugdir.list())
        self.buglist.sort()
        self.columns = ("id", "status", "severity", "summary")

        dataIndex = 0
        for x in range(len(self.columns)):
            self.InsertColumn(x, self.columns[x].capitalize())
            self.SetColumnWidth(x, wx.LIST_AUTOSIZE_USEHEADER)
        for bug in [b for b in self.buglist if b.active]:
            name = names.unique_name(bug, self.buglist)
            id = self.InsertStringItem(self.GetItemCount(), name)
            self.SetStringItem(id, 1, bug.status)
            self.SetStringItem(id, 2, bug.severity)
            self.SetStringItem(id, 3, bug.summary)
            self.SetItemData(id, dataIndex) # set keys for each line
            dataIndex += 1
            self.EnsureVisible(id)
        for x in range(len(self.columns)):
            self.SetColumnWidth(x, wx.LIST_AUTOSIZE)
            conts_width = self.GetColumnWidth(x)
            self.SetColumnWidth(x, wx.LIST_AUTOSIZE_USEHEADER)
            if conts_width > self.GetColumnWidth(x):
                self.SetColumnWidth(x, conts_width)

        self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColumnClick)
        self.bugcmp_fn = cmp_full
        # For reasons I don't understant, sorting is broken...
        #self.SortItems(self.Sorter)
        #self.Refresh()
    def Sorter(self, key1, key2):
        """Get bug info from the keys and pass to self.bugcmp_fn"""
        bug1 = self.buglist[key1-1]
        bug2 = self.buglist[key2-1]
        # Another way of getting bug information
        #bug1uuid = self.GetItem(key1, 0).GetText()
        #bug2uuid = self.GetItem(key2, 0).GetText()
        #print bug1uuid, bug2uuid
        #bug1 = self.bugdir.get_bug(bug1uuid)
        #bug2 = self.bugdir.get_bug(bug1uuid)
        print self.bugcmp_fn(bug1,bug2)
        return self.bugcmp_fn(bug1,bug2)
    def OnColumnClick(self, event):
        """Resort bug list depending on which column was clicked"""
        print "TODO: sort by column %d" % event.Column
        # change self.bugcmp_fn and resort, but I can't get it working

app = MyApp()
app.MainLoop()