1 | #Boa:FramePanel:Tab |
---|
2 | |
---|
3 | #************************************************************************* |
---|
4 | # Copyright (c) 2009-2010 The University of Chicago, as Operator of Argonne |
---|
5 | # National Laboratory. |
---|
6 | # Copyright (c) 2009-2010 The Regents of the University of California, as |
---|
7 | # Operator of Los Alamos National Laboratory. |
---|
8 | # This file is distributed subject to a Software License Agreement found |
---|
9 | # in the file LICENSE that is included with this distribution. |
---|
10 | #************************************************************************* |
---|
11 | |
---|
12 | ''' |
---|
13 | Define the GUI elements and interface for one tab (table) of the X,Y pair |
---|
14 | |
---|
15 | @version: |
---|
16 | ########### SVN repository information ################### |
---|
17 | # $Date: 2011-09-09 17:12:01 +0000 (Fri, 09 Sep 2011) $ |
---|
18 | # $Author: jemian $ |
---|
19 | # $Revision: 631 $ |
---|
20 | # $URL: wxmtxy/trunk/src/moxy/tab.py $ |
---|
21 | # $Id: tab.py 631 2011-09-09 17:12:01Z jemian $ |
---|
22 | ########### SVN repository information ################### |
---|
23 | ''' |
---|
24 | |
---|
25 | import wx |
---|
26 | import wxmtxy_row |
---|
27 | import wx.lib.scrolledpanel |
---|
28 | |
---|
29 | # Alternative is to use a wx.lib.scrolledpanel.ScrolledPanel |
---|
30 | # and call this method after subpanels have been created: |
---|
31 | # wx.lib.scrolledpanel.SetupScrolling(self, |
---|
32 | # scroll_x=False, scroll_y=True, |
---|
33 | # rate_x=20, rate_y=[get this from the subpanel height]) |
---|
34 | # Turns out the ScrolledPanel was developed for situations just like this! |
---|
35 | |
---|
36 | [wxID_TAB] = [wx.NewId() for _init_ctrls in range(1)] |
---|
37 | |
---|
38 | class Tab(wx.lib.scrolledpanel.ScrolledPanel): |
---|
39 | '''Create a panel to display rows of settings''' |
---|
40 | |
---|
41 | # see: http://wiki.wxpython.org/BoaFAQ |
---|
42 | _custom_classes = {'wx.Panel': ['Row']} |
---|
43 | |
---|
44 | def _init_sizers(self): |
---|
45 | # generated method, don't edit |
---|
46 | self.sizer = wx.BoxSizer(orient=wx.VERTICAL) |
---|
47 | |
---|
48 | self.SetSizer(self.sizer) |
---|
49 | |
---|
50 | def _init_ctrls(self, prnt): |
---|
51 | # generated method, don't edit |
---|
52 | wx.lib.scrolledpanel.ScrolledPanel.__init__(self, |
---|
53 | id=wxID_TAB, name='Tab', parent=prnt, |
---|
54 | pos=wx.Point(50, 39), size=wx.Size(408, 100), |
---|
55 | style=wx.TAB_TRAVERSAL) |
---|
56 | self.SetClientSize(wx.Size(400, 100)) |
---|
57 | self.SetMinSize(wx.Size(240, 75)) |
---|
58 | |
---|
59 | self._init_sizers() |
---|
60 | |
---|
61 | def __init__(self, parent, pair, pairCallback, newrow=False): |
---|
62 | '''create the panel''' |
---|
63 | self._init_ctrls(parent) |
---|
64 | self.pair = pair |
---|
65 | self.pairCallback = pairCallback |
---|
66 | if newrow == True: |
---|
67 | self.NewRow() # make the first row if requested |
---|
68 | |
---|
69 | # ################################ |
---|
70 | # ## added methods ### |
---|
71 | # ################################ |
---|
72 | |
---|
73 | def NewRow(self, remap = False): |
---|
74 | '''Make a new row and append it to the current tab |
---|
75 | @param remap: [Boolean] option to call self.Remap()''' |
---|
76 | panel = wxmtxy_row.Row(self, self.RowHandler) |
---|
77 | self.sizer.AddWindow(panel, 0, border=2, flag=wx.GROW) |
---|
78 | if remap: |
---|
79 | self.Remap() |
---|
80 | return panel |
---|
81 | |
---|
82 | def DeleteRow(self, theRow): |
---|
83 | '''Delete a row object |
---|
84 | @param theRow: ''' |
---|
85 | self.sizer.Detach(theRow) |
---|
86 | theRow.Destroy() |
---|
87 | self.Remap() |
---|
88 | |
---|
89 | def Remap(self): |
---|
90 | '''adjust the layout for any changes''' |
---|
91 | self.SetupScrolling(scroll_x=False, scroll_y=True, rate_x=1, rate_y=25) |
---|
92 | self.sizer.Layout() |
---|
93 | self.Layout() |
---|
94 | |
---|
95 | def RowHandler(self, theRow, command): |
---|
96 | '''Handle a command from a row''' |
---|
97 | #print 'RowHandler', command, theRow.GetLabel(), theRow.GetXY() |
---|
98 | (self.pairCallback)(self, theRow, command) |
---|
99 | |
---|
100 | def GetRowLabel(self, rownum): |
---|
101 | '''return the text in the label slot for the given row''' |
---|
102 | return self.sizer.GetItem(rownum).GetWindow().GetLabel() |
---|
103 | |
---|
104 | def SetRowLabel(self, rownum, label): |
---|
105 | '''set the text in the label slot for the given row''' |
---|
106 | self.sizer.GetItem(rownum).GetWindow().SetLabel(label) |
---|
107 | |
---|
108 | def GetRowXY(self, rownum): |
---|
109 | '''return the X,Y values in the label slot for the given row''' |
---|
110 | return self.sizer.GetItem(rownum).GetWindow().GetXY() |
---|
111 | |
---|
112 | def SetRowXY(self, rownum, x, y): |
---|
113 | '''set the text in the label slot for the given row''' |
---|
114 | self.sizer.GetItem(rownum).GetWindow().SetXY(x, y) |
---|
115 | |
---|
116 | # ################################ |
---|
117 | # ## event handling routines ### |
---|
118 | # ################################ |
---|
119 | |
---|
120 | # none |
---|