[Bio] / PyGUI / RXOnAddPageDialog.py Repository:
ViewVC logotype

Annotation of /PyGUI/RXOnAddPageDialog.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (view) (download) (as text)

1 : hwang 1.1 from wxPython.wx import *
2 :     from wxPython.grid import *
3 : efrank 1.3
4 : hwang 1.1 from PyGUI.MetabolitePanel import MetabolitePanel
5 : efrank 1.3 from PyGUI.EnzymeWindow import EnzymeWindow
6 : efrank 1.4 from KahOM.Reactant import Reactant
7 :     from KahOM.Reaction import Reaction
8 : hwang 1.1
9 :     import random
10 :    
11 :     class RXOnAddPageDialog(wxDialog):
12 :     # def __init__(self, parent, ID, title,
13 :     # def onDialogCancel(self, evt):
14 :     # def onDialogOK(self, evt):
15 :     # def getCellValuesFromEnzPage(self):
16 :     # def onSelectCell(self, evt):
17 :     # def GetValue( self ):
18 :     # def updateRxComboBox(self):
19 :    
20 :     #------------------------------------------------------------------------
21 :     def __init__(self, parent, ID, title,
22 :     pos=wxDefaultPosition, size=wxDefaultSize,
23 :     style=wxDEFAULT_DIALOG_STYLE):
24 :     #------------------------------------------------------------------------
25 :    
26 :    
27 :     wxDialog.__init__(self, parent, ID, title, pos, size, style)
28 :    
29 :     self.parent= parent
30 :    
31 :     self.onAddPagePanel = wxPanel(self, -1)
32 :    
33 :     self.addDialogBtn = wxButton(self.onAddPagePanel,-1, "add")
34 : hwang 1.5 self.cancelDialogBtn = wxButton(self.onAddPagePanel, wxID_CANCEL, "cancel")
35 :     self.previewBtn = wxButton(self.onAddPagePanel,-1, "preview")
36 : hwang 1.1
37 : hwang 1.5 self.rxCatalysisLabel = wxStaticText(self.onAddPagePanel, -1, "Catalysis ")
38 : efrank 1.6 self.rxDirectionLabel = wxStaticText(self.onAddPagePanel, -1, "Direction ")
39 : hwang 1.5 self.rxOutputLabel = wxStaticText(self.onAddPagePanel, -1, "Selected Outputs ")
40 :     self.rxPreviewLabel = wxStaticText(self.onAddPagePanel, -1, " press button to preview.")
41 : hwang 1.1
42 :     self.updateRxComboBox()
43 :    
44 : efrank 1.6 self.directionComboBox = wxComboBox(self.onAddPagePanel, -1, "both",
45 :     size=(150,-1), choices = ["both", "forward", "backward"],
46 :     style=wxCB_DROPDOWN | wxCB_READONLY)
47 :     self.directionComboBox.SetValue( "both" )
48 :    
49 :    
50 : hwang 1.1 self.onAddPageGrid = wxGrid(self.onAddPagePanel, -1)
51 :     self.onAddPageGrid.CreateGrid(0, 4)
52 :     self.onAddPageGrid.SetColLabelValue(0,"Input")
53 :     self.onAddPageGrid.SetColLabelValue(1,"Output")
54 :     self.onAddPageGrid.SetColLabelValue(2,"Stoich")
55 :     self.onAddPageGrid.AutoSizeColumn(2)
56 :     self.onAddPageGrid.SetColLabelValue(3,"Compound Name")
57 :     self.onAddPageGrid.AutoSizeColumn(3)
58 :    
59 :     self.onAddPageGrid.SetColFormatBool(0)
60 :     self.onAddPageGrid.SetColFormatBool(1)
61 :    
62 : hwang 1.5 onAddPageMainSizer = wxBoxSizer(wxVERTICAL)
63 :     dialogChoicesHSizer = wxBoxSizer(wxHORIZONTAL)
64 :     previewChoicesHSizer = wxBoxSizer(wxHORIZONTAL)
65 :    
66 :     previewChoicesHSizer.Add(self.previewBtn)
67 :     previewChoicesHSizer.Add(self.rxPreviewLabel)
68 :    
69 :     catalysisComboSizer = wxBoxSizer(wxHORIZONTAL)
70 :     catalysisComboSizer.Add(self.rxCatalysisLabel)
71 :     catalysisComboSizer.Add(self.rxCatalysisComboBox, 0, wxEXPAND)
72 :    
73 : efrank 1.6 directionComboSizer = wxBoxSizer(wxHORIZONTAL)
74 :     directionComboSizer.Add(self.rxDirectionLabel)
75 :     directionComboSizer.Add(self.directionComboBox, 0, wxEXPAND)
76 :    
77 :     catalysisDirectionHSizer = wxBoxSizer(wxHORIZONTAL)
78 :     catalysisDirectionHSizer.Add( catalysisComboSizer )
79 :     catalysisDirectionHSizer.Add( directionComboSizer )
80 :    
81 : hwang 1.5 dialogChoicesHSizer.Add (self.addDialogBtn)
82 :     dialogChoicesHSizer.Add (self.cancelDialogBtn)
83 : hwang 1.1
84 : hwang 1.5 onAddPageMainSizer.Add (self.onAddPageGrid, 7, wxEXPAND)
85 : efrank 1.6 #onAddPageMainSizer.Add (catalysisComboSizer)
86 :     onAddPageMainSizer.Add (catalysisDirectionHSizer)
87 : hwang 1.5 onAddPageMainSizer.Add (20,20, 0, wxEXPAND)
88 : efrank 1.6 onAddPageMainSizer.Add (previewChoicesHSizer)
89 : hwang 1.5 onAddPageMainSizer.Add (20,20, 0, wxEXPAND)
90 :     onAddPageMainSizer.Add (20,20, 0, wxEXPAND)
91 : efrank 1.6 onAddPageMainSizer.Add (dialogChoicesHSizer)
92 :     self.onAddPagePanel.SetSizer(onAddPageMainSizer)
93 :     self.onAddPagePanel.SetAutoLayout(true)
94 : hwang 1.1
95 :     self.getCellValuesFromEnzPage()
96 :    
97 : efrank 1.3 EVT_BUTTON(self, self.previewBtn.GetId(), self.onPreviewBtn)
98 : hwang 1.1 EVT_BUTTON(self, self.cancelDialogBtn.GetId(), self.onDialogCancel)
99 :     EVT_BUTTON(self, self.addDialogBtn.GetId(), self.onDialogAdd)
100 :     EVT_GRID_CELL_LEFT_CLICK(self, self.onSelectCell)
101 :    
102 :     return
103 :    
104 :     #------------------------------------------------------------------------
105 : efrank 1.3 def onPreviewBtn(self, evt):
106 :     #------------------------------------------------------------------------
107 : hwang 1.5 self.rxPreviewLabel.SetLabel( self.GetValue().asString() )
108 : efrank 1.3 return
109 :    
110 :     #------------------------------------------------------------------------
111 : hwang 1.1 def onDialogCancel(self, evt):
112 :     #------------------------------------------------------------------------
113 :     self.EndModal(wxID_CANCEL)
114 :     self.Destroy()
115 :     return
116 :    
117 :     #------------------------------------------------------------------------
118 :     def onDialogAdd(self, evt):
119 :     #------------------------------------------------------------------------
120 :     self.EndModal(wxID_OK)
121 :     #self.Destroy()
122 :     return
123 :    
124 :    
125 :    
126 :     #------------------------------------------------------------------------
127 :     def getCellValuesFromEnzPage(self):
128 :     #------------------------------------------------------------------------
129 :     #This function will be changed
130 :    
131 :     sourceRxGrid = self.parent.getSelectedMetabsGrid()
132 :     sourceRxGridRows = sourceRxGrid.GetNumberRows()
133 :    
134 :    
135 :     for rowNum in range(sourceRxGridRows):
136 :     sourceRxGrid.SelectRow(rowNum, True)
137 :    
138 :     stoichValue = sourceRxGrid.GetCellValue(rowNum,1)
139 :     compoundValue = sourceRxGrid.GetCellValue(rowNum,2)
140 :    
141 :     self.onAddPageGrid.AppendRows(numRows=1)
142 :     self.onAddPageGrid.SetCellValue(rowNum,0,'0' )
143 :     self.onAddPageGrid.SetCellValue(rowNum,1,'0' )
144 :     self.onAddPageGrid.SetCellValue(rowNum,2,'1')
145 :     self.onAddPageGrid.AutoSizeColumn(2)
146 :     self.onAddPageGrid.SetCellValue(rowNum,3, compoundValue)
147 :     self.onAddPageGrid.AutoSizeColumn(3)
148 :     self.onAddPageGrid.FitInside()
149 :    
150 :     return
151 :    
152 :     #------------------------------------------------------------------------
153 :     def onSelectCell(self, evt):
154 :     #------------------------------------------------------------------------
155 :    
156 :     cellRow = evt.GetRow()
157 :     cellCol = evt.GetCol()
158 :     cellValue = self.onAddPageGrid.GetCellValue(cellRow, cellCol)
159 :    
160 :     if (cellCol==0 or cellCol==1):
161 :     if (cellValue =='0'):
162 :     self.onAddPageGrid.SetCellValue(cellRow,cellCol, '1')
163 :     else:
164 :     self.onAddPageGrid.SetCellValue(cellRow,cellCol, '0')
165 : efrank 1.3 elif (cellCol == 2 ):
166 : hwang 1.5 print "rxOnAddPageDialog::onSelectCell: stoich is", cellValue
167 : hwang 1.1
168 :     return
169 :    
170 :     #------------------------------------------------------------------------
171 : efrank 1.3 def GetValue( self):
172 : hwang 1.1 #------------------------------------------------------------------------
173 : efrank 1.3 # Not really right...what if the selected goobers come from different
174 :     # factories? Then mixing this all together doesn't make sense. since
175 :     # we dont' track the foundryItemKey stuff right yet, we don't get
176 :     # in trouble. but its all a pack of lies at the moment.
177 : hwang 1.1
178 :    
179 : efrank 1.6 dir = self.directionComboBox.GetValue()
180 :    
181 : hwang 1.1 inputList = []
182 :     outputList= []
183 :    
184 :     for rowNum in range( self.onAddPageGrid.GetNumberRows() ):
185 :     isIn = self.onAddPageGrid.GetCellValue(rowNum,0)
186 :     isOut = self.onAddPageGrid.GetCellValue(rowNum,1)
187 : efrank 1.3 stoich = int( self.onAddPageGrid.GetCellValue(rowNum,2) )
188 :     theName = self.onAddPageGrid.GetCellValue(rowNum,3)
189 : hwang 1.1
190 : efrank 1.3 r = Reactant( theName, stoich)
191 :     if (isIn=="1") : inputList.append( r )
192 :     if (isOut=="1"): outputList.append( r )
193 : hwang 1.1
194 :    
195 : efrank 1.6 rx = Reaction(dir)
196 : efrank 1.3 rx.Inputs = inputList
197 :     rx.Outputs= outputList
198 : hwang 1.5 rx.enzymeNames = [ self.rxCatalysisComboBox.GetValue( ) ]
199 : hwang 1.1
200 : efrank 1.3 return rx
201 : hwang 1.1
202 :    
203 :     #------------------------------------------------------------------------
204 :     def updateRxComboBox( self):
205 :     #------------------------------------------------------------------------
206 :    
207 :    
208 : efrank 1.6 rxComboValues =["Unknown", "Spontaneous"]
209 : hwang 1.1
210 :     enzNumRows = self.parent.enzymesSelectedResultsGrid.GetNumberRows()
211 :    
212 :     for enzNum in range(enzNumRows):
213 :     enzValues = self.parent.enzymesSelectedResultsGrid.GetCellValue(enzNum,2)
214 :     rxComboValues.append(enzValues)
215 :    
216 : efrank 1.6 self.rxCatalysisComboBox = wxComboBox(self.onAddPagePanel, -1, "Unkown",
217 : hwang 1.1 size=(150,-1), choices = rxComboValues,
218 :     style=wxCB_DROPDOWN | wxCB_READONLY)
219 :    
220 : efrank 1.6 self.rxCatalysisComboBox.SetValue( "Unknown")
221 : hwang 1.1
222 : efrank 1.6 return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3