1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ########### SVN repository information ################### |
---|
4 | # $Date: 2011-12-20 04:37:56 +0000 (Tue, 20 Dec 2011) $ |
---|
5 | # $Author: jemian $ |
---|
6 | # $Revision: 729 $ |
---|
7 | # $URL$ |
---|
8 | # $Id: vc_pv.py 729 2011-12-20 04:37:56Z jemian $ |
---|
9 | ########### SVN repository information ################### |
---|
10 | |
---|
11 | ''' |
---|
12 | demo view for EPICS PV connection class: m_pv.PvConnection() |
---|
13 | |
---|
14 | Copyright (c) 2009 - 2011, UChicago Argonne, LLC. |
---|
15 | See LICENSE file for details. |
---|
16 | ''' |
---|
17 | |
---|
18 | |
---|
19 | # - - - - - - - - - - - - - - - - - - Imports |
---|
20 | |
---|
21 | |
---|
22 | import wx |
---|
23 | import wx.lib.buttons |
---|
24 | from m_pv import PvConnection |
---|
25 | |
---|
26 | |
---|
27 | # - - - - - - - - - - - - - - - - - - Global |
---|
28 | |
---|
29 | |
---|
30 | __svnid__ = "$Id: vc_pv.py 729 2011-12-20 04:37:56Z jemian $" |
---|
31 | |
---|
32 | |
---|
33 | # - - - - - - - - - - - - - - - - - - class |
---|
34 | |
---|
35 | |
---|
36 | class DemoView(wx.Frame): |
---|
37 | |
---|
38 | def __init__(self, pvname = ''): |
---|
39 | self.pvname = pvname |
---|
40 | wx.Frame.__init__(self, id=wx.ID_ANY, name=u'Frame1', |
---|
41 | parent=None, title=u'PV Connection',) |
---|
42 | #self.SetClientSize(wx.Size(732, 439)) |
---|
43 | self.SetToolTipString(u'PV Connection') |
---|
44 | |
---|
45 | self._init_widgets() |
---|
46 | self._init_sizers() |
---|
47 | |
---|
48 | def _init_widgets(self): |
---|
49 | self.panel = wx.Panel(id=wx.ID_ANY, name='panel1', parent=self) |
---|
50 | |
---|
51 | #self.sbTop = wx.StaticBox(id=wx.ID_ANY, |
---|
52 | # label=u'PV name and value', name='sbTop', parent=self.panel, size=wx.Size(300, 100),) |
---|
53 | #self.sbTop.SetToolTipString(u'PV name and value') |
---|
54 | |
---|
55 | #self.sbBottom = wx.StaticBox(id=wx.ID_ANY, |
---|
56 | # label='connection info', name='sbBottom', parent=self.panel, size=wx.Size(300, 100),) |
---|
57 | #self.sbBottom.SetToolTipString(u'EPICS connection info') |
---|
58 | |
---|
59 | self.genButton1 = wx.lib.buttons.GenButton(id=wx.ID_ANY, |
---|
60 | label=u'Connect', name='connectButton', parent=self.panel,) |
---|
61 | self.genButton1.SetToolTipString(u'Connect with EPICS PV') |
---|
62 | self.genButton1.Bind(wx.EVT_BUTTON, self.doConnectButton) |
---|
63 | |
---|
64 | self.genButton2 = wx.lib.buttons.GenButton(id=wx.ID_ANY, |
---|
65 | label=u'Disconnect', name='disconnectButton', parent=self.panel,) |
---|
66 | self.genButton2.SetToolTipString(u'Disconnect from EPICS PV') |
---|
67 | self.genButton2.Bind(wx.EVT_BUTTON, self.doDisconnectButton) |
---|
68 | |
---|
69 | # wx.StaticBoxSizer( wx.StaticBox( parent_window, id, "label" ), wx.HORIZONTAL ) |
---|
70 | |
---|
71 | def _init_sizers(self): |
---|
72 | self.panelSizer = wx.BoxSizer(orient=wx.VERTICAL) |
---|
73 | self.panel.SetSizer(self.panelSizer) |
---|
74 | #self.panelSizer.AddWindow(self.sbTop, proportion=1, border=0, flag=wx.EXPAND) |
---|
75 | #self.panelSizer.AddWindow(self.sbBottom, proportion=1, border=0, flag=wx.EXPAND) |
---|
76 | self.buttonSizer = wx.BoxSizer(orient=wx.HORIZONTAL) |
---|
77 | self.panelSizer.AddSizer(self.buttonSizer, 0, border=0, flag=wx.EXPAND) |
---|
78 | self.buttonSizer.AddWindow(self.genButton1, proportion=1, border=0, flag=wx.EXPAND) |
---|
79 | self.buttonSizer.AddWindow(self.genButton2, proportion=1, border=0, flag=wx.EXPAND) |
---|
80 | |
---|
81 | #self.sbTopSizer = wx.StaticBoxSizer(self.sbTop, wx.VERTICAL) |
---|
82 | #self.sbBottomSizer = wx.StaticBoxSizer(self.sbBottom, wx.VERTICAL ) |
---|
83 | |
---|
84 | def _example_(self, parent): |
---|
85 | ''' |
---|
86 | StaticBoxSizer example |
---|
87 | |
---|
88 | create the control items, |
---|
89 | defines self.motorList dictionary, |
---|
90 | returns FlexGridSizer object |
---|
91 | ''' |
---|
92 | sbox = wx.StaticBox(parent, id=wx.ID_ANY, |
---|
93 | label='watch EPICS motors', style=0) |
---|
94 | sbs = wx.StaticBoxSizer(sbox, wx.VERTICAL) |
---|
95 | fgs = wx.FlexGridSizer(rows=4, cols=3, hgap=4, vgap=4) |
---|
96 | |
---|
97 | # column labels |
---|
98 | for item in self.AXIS_LABELS: |
---|
99 | fgs.Add( |
---|
100 | wx.StaticText(parent, wx.ID_ANY, item), |
---|
101 | 0, flag=wx.EXPAND) |
---|
102 | # one motor axis per row |
---|
103 | self.motorList = {} |
---|
104 | for axis in self.AXIS_NAMES: |
---|
105 | fgs.Add( |
---|
106 | wx.StaticText(parent, wx.ID_ANY, axis, style=wx.ALIGN_RIGHT), |
---|
107 | 0, flag=wx.EXPAND) |
---|
108 | D = {} |
---|
109 | for field in self.AXIS_FIELDS: |
---|
110 | text = '[%s].%s' % (axis, field) |
---|
111 | widget = wx.TextCtrl(parent, wx.ID_ANY, text, style=wx.TE_READONLY|wx.ALIGN_RIGHT) |
---|
112 | widget.SetBackgroundColour(self.NOT_MOVING_COLOR) |
---|
113 | widget.SetToolTipString("motor,%s,%s" % (axis, field)) |
---|
114 | widget.SetFont(self.basicFont) |
---|
115 | fgs.Add(widget, 0, flag=wx.EXPAND) |
---|
116 | D[field] = widget |
---|
117 | self.motorList[axis] = D |
---|
118 | |
---|
119 | fgs.AddGrowableCol(1) |
---|
120 | fgs.AddGrowableCol(2) |
---|
121 | |
---|
122 | sbs.Add(fgs, 0, wx.EXPAND|wx.ALIGN_CENTRE|wx.ALL, 5) |
---|
123 | |
---|
124 | return sbs |
---|
125 | |
---|
126 | def doConnectButton(self, event): |
---|
127 | event.Skip() |
---|
128 | print "Connect button pressed" |
---|
129 | |
---|
130 | def doDisconnectButton(self, event): |
---|
131 | event.Skip() |
---|
132 | print "Disconnect button pressed" |
---|
133 | |
---|
134 | |
---|
135 | # - - - - - - - - - - - - - - - - - - methods |
---|
136 | |
---|
137 | |
---|
138 | # - - - - - - - - - - - - - - - - - - main |
---|
139 | |
---|
140 | |
---|
141 | if __name__ == '__main__': |
---|
142 | app = wx.PySimpleApp() |
---|
143 | frame = DemoView('Godzilla') |
---|
144 | frame.Show() |
---|
145 | |
---|
146 | app.MainLoop() |
---|