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