OpenMPCD
PlotSelectionList.py
1 from .. import Exceptions
2 
3 import wx.lib.mixins.listctrl
4 
5 # see http://code.activestate.com/recipes/426407-columnsortermixin-with-a-virtual-wxlistctrl/
6 
7 class PlotSelectionList(wx.ListCtrl, wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin, wx.lib.mixins.listctrl.ColumnSorterMixin):
8  """
9  List of plots and their characteristics, which can be used to select which plots to draw.
10  """
11 
12  def __init__(self, parent, plotter):
13  wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES)
14 
15  self.plotter = plotter
16  self.plotter._registerPlotSelector(self)
17 
18  self.images = {}
19  self.imagelist = wx.ImageList(16, 16)
20  self.images['sort_down'] = self.imagelist.Add(wx.ArtProvider.GetBitmap(wx.ART_GO_DOWN, wx.ART_TOOLBAR, (16, 16)))
21  self.images['sort_up'] = self.imagelist.Add(wx.ArtProvider.GetBitmap(wx.ART_GO_UP, wx.ART_TOOLBAR, (16, 16)))
22  self.images['tick_mark'] = self.imagelist.Add(wx.ArtProvider.GetBitmap(wx.ART_TICK_MARK, wx.ART_TOOLBAR, (16, 16)))
23  self.images['cross_mark'] = self.imagelist.Add(wx.ArtProvider.GetBitmap(wx.ART_CROSS_MARK, wx.ART_TOOLBAR, (16, 16)))
24  self.SetImageList(self.imagelist, wx.IMAGE_LIST_SMALL)
25 
26  wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin.__init__(self)
27  wx.lib.mixins.listctrl.ColumnSorterMixin.__init__(self, 0)
28 
29  self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
30 
31  def getColumnName(self, column):
32  """
33  Returns a column'a name.
34 
35  @param[in] column The column ID, from the range [0, GetColumnCount()).
36  @throw OutOfRangeException Throws if column is out of range.
37  """
38 
39  if column >= self.GetColumnCount():
40  raise Exceptions.OutOfRangeException("'column' out of range.")
41 
42  return self.GetColumn(column).GetText()
43 
44  def getItemIndex(self, item):
45  return self.itemIndexMap[item]
46 
47  def getItemData(self, item):
48  return self.itemDataMap[self.getItemIndex(item)]
49 
50  def getItemColumn(self, item, column):
51  itemData = self.getItemData(item)
52  return itemData[column]
53 
54  def GetListCtrl(self):
55  return self
56 
57  def GetSortImages(self):
58  return (self.images['sort_down'], self.images['sort_up'])
59 
60  def OnGetItemText(self, item, col):
61  return self.getItemColumn(item, col)
62 
63  def OnGetItemImage(self, item):
64  if self.getItemColumn(item, 0):
65  return self.images['tick_mark']
66 
67  return self.images['cross_mark']
68 
69  def OnGetItemAttr(self, item):
70  return None
71 
72  def SortItems(self, sorter):
73  items = list(self.itemDataMap.keys())
74  items.sort(sorter)
75  self.itemIndexMap = items
76  self.Refresh()
77 
78  def OnItemActivated(self, event):
79  self.plotter.toggleVisibility(self.itemIndexMap[event.m_itemIndex])
MPCDAnalysis.Exceptions.OutOfRangeException
Definition: Exceptions.py:21
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.getItemData
def getItemData(self, item)
Definition: PlotSelectionList.py:49
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.OnItemActivated
def OnItemActivated(self, event)
Definition: PlotSelectionList.py:80
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.itemIndexMap
itemIndexMap
Definition: PlotSelectionList.py:77
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.plotter
plotter
Definition: PlotSelectionList.py:16
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.getColumnName
def getColumnName(self, column)
Definition: PlotSelectionList.py:39
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.images
images
Definition: PlotSelectionList.py:19
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.getItemColumn
def getItemColumn(self, item, column)
Definition: PlotSelectionList.py:52
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.imagelist
imagelist
Definition: PlotSelectionList.py:20
MPCDAnalysis.InteractivePlotter.PlotSelectionList.PlotSelectionList.getItemIndex
def getItemIndex(self, item)
Definition: PlotSelectionList.py:46