1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
21 from wx.lib.mixins.listctrl import CheckListCtrlMixin
25 class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin):
26 def __init__(self, parent):
27 wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)
28 CheckListCtrlMixin.__init__(self)
29 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
31 def OnItemActivated(self, evt):
32 self.ToggleItem(evt.m_itemIndex)
35 class Results(wx.Panel):
36 def __init__(self, parent):
37 wx.Panel.__init__(self, parent, -1)
38 self.results_list = CheckListCtrl(self)
40 sizer.Add(self.results_list, 1, wx.EXPAND)
42 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.results_list)
43 self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.results_list)
44 #self.results_list.OnCheckItem = self.OnCheckItem
46 def _GetWidthInPixels(self, text):
48 #Returns the width of a string in pixels
49 #Unfortunately, it does not work terribly well (although it should).
50 #Thus, we have to add a bit afterwards.
51 #Annoys the heck out of me.
52 font = self.results_list.GetFont()
53 dc = wx.WindowDC(self.results_list)
55 width, height = dc.GetTextExtent(text)
58 def ClearResults(self):
59 self.results_list.ClearAll()
61 def DisplayResults(self, results):
63 header = results.header_as_list()
64 self.results_list.InsertColumn(0, 'Show')
65 for index, column in enumerate(header):
66 self.results_list.InsertColumn(index + 1, column, wx.LIST_FORMAT_RIGHT)
68 for result in results.results:
70 for index, column in enumerate(results.columns):
71 value_str = results.get_pretty_value(column, result.result[column])
73 index_col = self.results_list.InsertStringItem(sys.maxint, '')
75 column_width = len(self.results_list.GetColumn(index + 1).GetText())
76 value_str = value_str.center(column_width)
77 self.results_list.SetStringItem(index_col, index + 1, value_str)
78 #self.results_list.SetItemData(index, result)
80 for index, result in enumerate(results.results):
82 #if we use 'CheckItem' then 'UpdatePlot' is called (ie repeated updates)
83 self.results_list.SetItemImage(index, 1)
84 #self.results_list.CheckItem(index)
85 for index in range(self.results_list.GetColumnCount()):
86 column_text = self.results_list.GetColumn(index).GetText()
87 column_width = self._GetWidthInPixels(column_text)
88 self.results_list.SetColumnWidth(index, column_width + 15)
90 def OnItemSelected(self, evt):
93 def OnItemDeselected(self, evt):