Exemplo n.º 1
0
    def __init__(self, parent, interpParent, port, dispInfo=None, id=-1, pos=None, size=None):
        #w, h =  parent.GetSizeTuple()
        if not pos: pos = wxDefaultPosition
        if not size: size = wxSize(300, 300)
        wxGrid.__init__(self, parent, id, pos, size)
        
        self._wait = 0
        self._waitRow = None
        self._waitCol = None
        self._waitOldVal = None

        self.interpParent = interpParent
        if not dispInfo: dispInfo = PortDisplayInfo()
        self.info = dispInfo
        
        self.unitSystem = S42Glob.unitSystem

        self.CreateGrid(1, 2) #One row to begin with
        self.SetCellEditor(0, VALUE_COL, GridEditors.PropEditor(self))
        self.SetCellRenderer(0, VALUE_COL, GridRenderers.PropRenderer(self))
        self.SetCellEditor(0, UNITS_COL, GridEditors.UnitEditor(self))
        self.SetCellRenderer(0, UNITS_COL, GridRenderers.UnitRenderer(self))
        
        self.SetRowLabelSize(120)
        self.SetColLabelValue(0, "Value")
        self.SetColLabelValue(1, "Units")
        
        EVT_LEFT_DOWN(self.GetGridWindow(), self.OnLeftDown) 
        EVT_GRID_CELL_LEFT_DCLICK(self, self.OnCellLeftDClick)
        EVT_GRID_CELL_CHANGE(self, self.OnCellChange)

        self.SetPort(port) #This updates the view
Exemplo n.º 2
0
 def UpdateFromUOSelect(self, col, uoName):
     parentFlowsh = self.interpParent.GetParentFlowsh()
     portsNames = parentFlowsh.chUODict[uoName].GetPortNames(MAT|ENE|IN|OUT)
     self.grid.SetCellValue(1, col, portsNames[0])
     ed = wxGridCellChoiceEditor(portsNames, false)
     self.grid.SetCellEditor(1, col, ed)
     self.grid.SetCellRenderer(1, col, GridRenderers.SCellRendererTitleChoice())
     self.UpdateFromPortSelect(col, uoName, portsNames[0])
Exemplo n.º 3
0
 def DefineEditorAndRenderer(self, status, grid, row, col):
     grid.SetCellRenderer(row, col, GridRenderers.PropRenderer(status))
     if status & (CALCULATED_V | PASSED_V):
         grid.SetReadOnly(row, col, true)
     elif status & FIXED_V:
         grid.SetCellEditor(row, col, GridEditors.PropEditor(grid))
         grid.SetReadOnly(row, col, false)
     else :
         grid.SetCellEditor(row, col, GridEditors.PropEditor(grid))
         grid.SetReadOnly(row, col, false)
Exemplo n.º 4
0
    def UpdateView(self):
        #Don't update if it is on wait
        if self._wait: return #Leave!!!!
        
        propNames = self.info.GetPropList()
        units = self.info.GetUnitList()
        portProps = self.port.GetProperties()
        nuProps = len(propNames)

        r = self.GetNumberRows()
        if nuProps < r: self.DeleteRows(nuProps, r - nuProps)
        elif nuProps > r: self.AppendRows(nuProps - r)
        for i in range(r, nuProps):
            self.SetCellEditor(i, VALUE_COL, GridEditors.PropEditor(self))
            self.SetCellRenderer(i, VALUE_COL, GridRenderers.PropRenderer(self))
            self.SetCellEditor(i, UNITS_COL, GridEditors.UnitEditor(self))
            self.SetCellRenderer(i, UNITS_COL, GridRenderers.UnitRenderer(self))
        for i in range(nuProps):
            propName = propNames[i]
            unit = units[i]
            self.UpdateRow(i, portProps[propName], unit)
        self.ForceRefresh()
Exemplo n.º 5
0
    def UpdateView(self):
        """Update what the controls show"""

        #Get the termo info
        thAdmin = self.interpParent.GetThAdmin()
        selCmps = thAdmin.GetSelectedCompoundNames(self.provider, self.thName)
        pkgStr = thAdmin.GetPropPkgString(self.provider, self.thName)

        #Resize the grid
        r = self.ipGrid.GetNumberRows()
        c = self.ipGrid.GetNumberCols()
        nuCmps = len(selCmps)
        if nuCmps < r: self.ipGrid.DeleteRows(0, r - nuCmps)
        elif nuCmps > r: self.ipGrid.AppendRows(nuCmps - r)
        if nuCmps < c: self.ipGrid.DeleteCols(0, c - nuCmps)
        elif nuCmps > c: self.ipGrid.AppendCols(nuCmps - c)
        for i in range(nuCmps):
            self.ipGrid.SetColLabelValue(i, selCmps[i])
            self.ipGrid.SetRowLabelValue(i, selCmps[i])
            self.ipGrid.SetCellValue(i, i, '--')
            self.ipGrid.SetReadOnly(i, i)
            for j in range(nuCmps):
                if i != j:
                    self.ipGrid.SetCellEditor(
                        i, j, GridEditors.NumberEditor(self.ipGrid))
                    self.ipGrid.SetCellRenderer(
                        i, j, GridRenderers.NumberRenderer(self.ipGrid))
        self.ipGrid.ForceRefresh()

        #Fill in the prop pkg name, the choice boxes and the grid
        self.chIPMatrix.Clear()
        self.lblPropPkgDesc.SetLabel(pkgStr)
        ipMatrNames = thAdmin.GetIPMatrixNames(self.provider, self.thName)
        if ipMatrNames:
            for i in ipMatrNames:
                self.chIPMatrix.Append(i)
            self.chIPMatrix.SetStringSelection(ipMatrNames[0])
        self.UpdateFromIPMatrixSelect()
Exemplo n.º 6
0
    def UpdateView(self):
        uos, ports = self.tableInfo.GetUOPortLists()
        parentFlowsh = self.interpParent.GetParentFlowsh()
        uoNames = parentFlowsh.GetChildUONames()

        #Make sure uos are still there
        toDel = []
        for i in range(len(uos)):
            if uos[i] not in uoNames:
                toDel.append(i)
        toDel.reverse()
        for i in toDel: tableInfo.DelPort(i)

        #Update nu of rows
        props = self.tableInfo.GetPropList()
        r = self.grid.GetNumberRows() - self._rOffset
        nuProps = len(props)
        #Weird bug in wxPython where for some reason, the last row HAS
        #to be deleted and recreated to prevent a crash if a change
        #last occured in the last row
        if r:
            self.grid.DeleteRows(r-1+self._rOffset, 1)
            r = r - 1
        if nuProps < r: self.grid.DeleteRows(self._rOffset, r - nuProps)
        elif nuProps > r: self.grid.AppendRows(nuProps - r)

        #Update nu of cols
        c = self.grid.GetNumberCols() - self._cOffset
        nuUO = len(uos)
        if nuUO < c: self.grid.DeleteCols(self._cOffset, c - nuUO)
        elif nuUO > c: self.grid.AppendCols(nuUO - c)

        #Set values of props
        for i in range(nuProps):
            self.grid.SetCellValue(self._rOffset + i, 0, props[i])
            ed = wxGridCellChoiceEditor(list(self.avProps), false)
            self.grid.SetCellEditor(self._rOffset + i, 0, ed)
            self.grid.SetCellRenderer(self._rOffset + i, 0, GridRenderers.SCellRendererTitleChoice())
        
        #Now do the ports
        if not len(uos):
            #If there is nothing there, init with two ports
            if len(uoNames) > 0:
                for i in range(2):
                    self.grid.AppendCols(1)
                    self.grid.SetCellValue(0, self._cOffset + i, uoNames[0])
                    self.UpdateFromUOSelect(self._cOffset + i, uoNames[0])
                    ed = wxGridCellChoiceEditor(uoNames, false)
                    self.grid.SetCellEditor(0, self._cOffset + i, ed)
                    self.grid.SetCellRenderer(0, self._cOffset + i, GridRenderers.SCellRendererTitleChoice())
        else:
            cols = self.grid.GetNumberCols()
            toDel = []
            count = 0
            for i in range(len(uos)):
                portsNames = parentFlowsh.chUODict[uos[i]].GetPortNames(MAT|ENE|IN|OUT)
                #First check that the port is still there
                if not ports[i] in portsNames:
                    toDel.append(i)
                else:
                    if count >= self.grid.GetNumberCols() - self._cOffset: self.grid.AppendCols(1)
                    self.grid.SetCellValue(0, count + self._cOffset, uos[i])
                    ed = wxGridCellChoiceEditor(uoNames, false)
                    self.grid.SetCellEditor(0, count + self._cOffset, ed)
                    self.grid.SetCellRenderer(0, count + self._cOffset, GridRenderers.SCellRendererTitleChoice())

                    self.grid.SetCellValue(1, count + self._cOffset, ports[i])
                    ed = wxGridCellChoiceEditor(portsNames, false)
                    self.grid.SetCellEditor(1, count + self._cOffset, ed)
                    self.grid.SetCellRenderer(1, count + self._cOffset, GridRenderers.SCellRendererTitleChoice())
                    self.UpdateColVals(count + self._cOffset, uos[i], ports[i])
                    count += 1
            toDel.reverse()
            for i in toDel: tableInfo.DelPort(i)
Exemplo n.º 7
0
    def __init__(self, parent, interpParent, tableInfo, id=-1, pos=None, size=None):
        w, h =  parent.GetSizeTuple()
        if not pos: pos = wxPoint(0,0)
        if not size: size = wxSize(w, h)
        wxPanel.__init__(self, parent, id, pos, size)

        #Rows and columns used for titles
        self._rOffset = 2
        self._cOffset = 1

        #Basic info
        self.tableInfo = tableInfo
        self.interpParent = interpParent
        parentFlowsh = self.interpParent.GetParentFlowsh()

        #Available props for selection        
        thAdmin = self.interpParent.GetThAdmin()
        providers = thAdmin.GetAvThermoProviderNames()
        self.avProps = []
        if len(providers) > 0:
            self.avProps.extend([MOLEFLOW_VAR, MASSFLOW_VAR, ENERGY_VAR])
            self.avProps.extend(thAdmin.GetPropertyNames(providers[0]))
        else:
            self.avProps.extend(GetCommonProps())
        self.avProps.sort()
        
        parentFlowsh = self.interpParent.GetParentFlowsh()
        uoNames = parentFlowsh.GetChildUONames()
        
        button = wxButton(self, -1, "Add Port", wxPoint(5, 5))
        EVT_BUTTON(self, button.GetId(), self.OnAddPort)
        if len(uoNames) <= 0: button.Enable(false)
        
        button = wxButton(self, -1, "Add Prop", wxPoint(145, 5))
        EVT_BUTTON(self, button.GetId(), self.OnAddProp)       

        #Create grid
        self.grid = wxGrid(self, -1, wxPoint(10, 40), wxSize(500, 250))
        self.grid.SetDefaultCellBackgroundColour(wxLIGHT_GREY)
        self.grid.CreateGrid(self._rOffset, self._cOffset)
        self.grid.SetRowLabelSize(0)
        self.grid.SetColLabelSize(0)
        self.grid.SetGridLineColour(wxBLACK)
        
        #Block the top left cells
        self.grid.SetCellRenderer(0, 0, GridRenderers.SCellRendererTitle())
        self.grid.SetReadOnly(0, 0, true)
        self.grid.SetCellRenderer(1, 0, GridRenderers.SCellRendererTitle())
        self.grid.SetReadOnly(1, 0, true)

        #Events        
##        EVT_MOTION(self.grid.GetGridWindow(), self.OnMouseMotion)   
        EVT_GRID_CELL_LEFT_DCLICK(self.grid, self.OnCellLeftDClick)
        EVT_GRID_CELL_CHANGE(self.grid, self.OnCellChange)
        #Pop up editing control with a single click
        self.__enableEdit = 0
        EVT_IDLE(self.grid, self.__OnIdle)
##        EVT_GRID_CELL_LEFT_CLICK(self.grid, self.__OnSelectCell)
        EVT_GRID_CELL_RIGHT_CLICK(self.grid, self.OnDoPopup)
        EVT_GRID_SELECT_CELL(self.grid, self.OnGridSelectCell)
        EVT_GRID_RANGE_SELECT(self.grid, self.OnRangeSelect)
        
        self.UpdateView()
Exemplo n.º 8
0
    def UpdateView(self):

        #Don't update if it is on wait
        if self._wait: return #Leave!!!!
        
        cmpNames = self.port.GetCompoundNames()
        nuCmps = len(cmpNames)
        
        #Let's work on the columns first
        if self.redoCols:

            if self.edit == FRAC_VAR: self.fracType |= SHOW_MOLFRAC
            elif self.edit == MASSFRAC_VAR: self.fracType |= SHOW_MASSFRAC
            
            self.colsOrder = []
            if self.fracType & SHOW_MOLFRAC: self.colsOrder.append(SHOW_MOLFRAC)
            if self.fracType & SHOW_MASSFRAC: self.colsOrder.append(SHOW_MASSFRAC)
            if self.fracType & SHOW_VOLFRAC: self.colsOrder.append(SHOW_VOLFRAC)
            
            if self.edit == FRAC_VAR: self.editCol = self.colsOrder.index(SHOW_MOLFRAC)
            elif self.edit == MASSFRAC_VAR: self.editCol = self.colsOrder.index(SHOW_MASSFRAC)

            nuCols = len(self.colsOrder)
            c = self.GetNumberCols()
            if nuCols < c: self.DeleteCols(nuCols, c - nuCols)
            elif nuCols > c: self.AppendCols(nuCols - c)
            for row in range(self.GetNumberRows()):
                for col in range(c, nuCols):
                    self.SetCellEditor(row, col, GridEditors.CompEditor(self))
                    self.SetCellRenderer(row, col, GridRenderers.CompRenderer(self))
        
            for i in range(nuCols):
                if self.colsOrder[i] == SHOW_MOLFRAC: lbl = self.LBL_MOLFRAC
                elif self.colsOrder[i] == SHOW_MASSFRAC: lbl = self.LBL_MASSFRAC
                elif self.colsOrder[i] == SHOW_VOLFRAC: lbl = self.LBL_VOLFRAC
                self.SetColLabelValue(i, lbl)
                self.SetColSize(i, 90)
            self.redoCols = false

        r = self.GetNumberRows()
        if nuCmps < r: self.DeleteRows(nuCmps, r - nuCmps)
        elif nuCmps > r: self.AppendRows(nuCmps - r)

        for i in range(r, nuCmps):
            for col in range(len(self.colsOrder)):
                self.SetCellEditor(i, col, GridEditors.CompEditor(self))
                self.SetCellRenderer(i, col, GridRenderers.CompRenderer(self))

        #Set the values
        molFracs = self.port.GetObject(FRAC_VAR)
        for cmp in range(nuCmps): 
            self.SetRowLabelValue(cmp, cmpNames[cmp])
        for col in range(len(self.colsOrder)):
            if self.colsOrder[col] == SHOW_MOLFRAC: fracs = molFracs.GetValues()
            elif self.colsOrder[col] == SHOW_MASSFRAC: fracs = self.port.GetObject(MASSFRAC_VAR).GetValues()
            elif self.colsOrder[col] == SHOW_VOLFRAC: fracs = self.port.GetObject(FRAC_VAR).GetValues()
            for cmp in range(nuCmps): 
                self.SetCellValue(cmp, col, str(fracs[cmp]))

                status = molFracs[cmp].GetCalcStatus()
                rend = self.GetCellRenderer(cmp, col)
                if hasattr(rend, 'SetStatusFlag'):
                    rend.SetStatusFlag(status)
                    fnt = rend.GetFont()
                    self.SetCellFont(cmp, col, fnt)
                if status & (CALCULATED_V | PASSED_V): self.SetReadOnly(cmp, col, true)
                else: self.SetReadOnly(cmp, col, false)
                if col != self.editCol: self.SetReadOnly(cmp, col, true)

        self.ForceRefresh()