Пример #1
0
    def excel_to_grid(self, source, sheet, grid):
        """
        Opens the Excel file in source and loads the sheet into the grid
        nx is the number of extra columns required.
        """

        wb = xlrd.open_workbook(source)
        names = wb.sheet_names()

        if sheet in names:
            grid.ClearGrid()
            if grid.GetNumberRows() > 0:
                grid.DeleteRows(0, grid.GetNumberRows(), True)
            if grid.GetNumberCols() > 0:
                grid.DeleteCols(0, grid.GetNumberCols(), True)

            sh = wb.sheet_by_name(sheet)
            num_rows = sh.nrows
            num_cols = sh.ncols
            self.SetGridRows(grid, num_rows)
            self.SetGridCols(grid, num_cols)  #extra columns for results
            #print 'number of rows = ', num_rows
            #print 'number of columns = ', num_cols
            curr_row = -1
            while curr_row < num_rows - 1:
                curr_row += 1
                for i in range(num_cols):
                    grid.SetCellValue(curr_row, i, self.style(sh, curr_row, i))
            return True
        else:
            return False
    def update_grid(self, *args):
        """Fill the grid rows with data, and set the right editors."""
        # @type grid wx.grid.Grid
        grid = self.panel.gridExp

        #Adjust number of rows
        num_rows = len(model.instrument.inst.positions)
        if grid.GetNumberRows() > num_rows:
            grid.DeleteRows(0, grid.GetNumberRows() - num_rows)
        else:
            old_num_rows = grid.GetNumberRows()
            grid.AppendRows(num_rows - grid.GetNumberRows())
            #Set the editors for the new rows
            choices = model.experiment.get_stopping_criteria_names()
            for row in xrange(old_num_rows, num_rows):
                grid.SetCellEditor(row, self.criterion_col,
                                   wx.grid.GridCellChoiceEditor(choices))

        #Font for angles
        angle_font = wx.Font(10, 76, wx.NORMAL, wx.NORMAL, False, u'Monospace')
        for (i, poscov) in enumerate(model.instrument.inst.positions):
            row = i
            #The checkbox
            grid.SetCellAlignment(row, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
            grid.SetReadOnly(row, 0, True)  #Do set it read-only
            #The angles
            for (j, angleinfo) in enumerate(model.instrument.inst.angles):
                x = poscov.angles[j]
                col = j + 1
                grid.SetCellValue(row, col,
                                  u"%8.2f" % angleinfo.internal_to_friendly(x))
                grid.SetReadOnly(row, col, True)  #Do set it read-only
                grid.SetCellAlignment(row, col, wx.ALIGN_CENTRE,
                                      wx.ALIGN_CENTRE)
                grid.SetCellFont(row, col, angle_font)
            #The criterion
            grid.SetCellValue(
                row, self.criterion_col,
                model.experiment.get_stopping_criterion_friendly_name(
                    poscov.criterion))
            grid.SetCellValue(row, self.criterion_col + 1,
                              str(poscov.criterion_value))
            #Comment string
            grid.SetCellValue(row, self.criterion_col + 2, str(poscov.comment))

        self.update_selection()
Пример #3
0
def setup_grid(grid, title):
    """
    This function only works with type wx.grid.Grid
    The it will create a grid that is like the one found in LinkCtrl/View.
    :param grid:
    :return:
    """

    grid.CreateGrid(6, 2)
    grid.EnableEditing(False)
    grid.EnableGridLines(True)
    grid.SetGridLineColour(wx.Colour(0, 0, 0))
    grid.EnableDragGridSize(False)

    # Columns
    grid.EnableDragColMove(False)
    grid.EnableDragColSize(True)
    grid.SetColLabelSize(0)
    grid.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
    grid.SetColSize(0, 110)

    # Rows
    grid.EnableDragRowSize(True)
    grid.SetRowLabelSize(0)
    grid.SetRowLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)

    # Defaults
    grid.SetDefaultCellBackgroundColour(wx.Colour(255, 255, 255))  # white
    grid.SetDefaultCellAlignment(wx.ALIGN_LEFT, wx.ALIGN_TOP)

    # Set Cell Values
    grid.SetCellValue(0, 0, " %s" % title)
    grid.SetCellValue(1, 0, " Variable Name")
    grid.SetCellValue(2, 0, " Geometry Type")
    grid.SetCellValue(3, 0, " Geometry Count")
    grid.SetCellValue(4, 0, " Coordinate System")
    grid.SetCellValue(5, 0, " Spatial Extent")

    # set the default background color
    grid.SetDefaultCellBackgroundColour('WHITE')

    # change color and size of header
    grid.SetCellSize(0, 0, 1, 2)  # span cols 0 and 1
    grid.SetCellBackgroundColour(0, 0, wx.Colour(195, 195, 195))  # Grey

    # set the table column size
    grid.SetColSize(0, 133)
    grid.SetColSize(1, 155)

    # change color of properties
    for i in range(1, grid.GetNumberRows()):
        grid.SetCellBackgroundColour(i, 0, wx.Colour(250, 250,
                                                     250))  # light Grey

    grid.SetGridLineColour(wx.Colour(195, 195, 195))
Пример #4
0
    def __init__(self,
                 parent,
                 grid,
                 format=[],
                 total_col=None,
                 total_row=None,
                 rowLabels=True,
                 colLabels=True):
        if total_row is None:
            total_row = grid.GetNumberRows()
        if total_col is None:
            total_col = grid.GetNumberCols()

        self.total_row = total_row
        self.total_col = total_col
        self.grid = grid
        self.rowLabels = rowLabels
        self.colLabels = colLabels

        data = []
        for row in range(total_row):
            row_val = []
            if rowLabels:
                row_val.append(grid.GetRowLabelValue(row))

            for col in range(total_col):
                try:
                    row_val.append(grid.GetCellValueAsString(row, col))
                except:
                    row_val.append(grid.GetCellValue(row, col))
            data.append(row_val)

        if colLabels:
            label = [""] if rowLabels else []
            for col in range(total_col):
                value = grid.GetColLabelValue(col)
                label.append(value)

        d = float(grid.GetColSize(0))
        if format == []:
            if rowLabels:
                format.append(grid.GetRowLabelSize())
            for col in range(total_col):
                col_size = grid.GetColSize(col)
                #print("Column size:", col,'\t',col_size)
                format.append(col_size)

        self.table = PrintTable(parent, rowLabels, colLabels)
        if colLabels: self.table.label = label
        self.table.cell_left_margin = 0.0
        self.table.cell_right_margin = 0.0

        self.table.set_column = format
        self.table.data = data
Пример #5
0
 def update_grid(self):
     """Update the grid after the table data has changed"""
     need_column_layout = False
     grid = self.grid
     v = self.v
     if len(v.column_names) < grid.GetNumberCols():
         tm = wx.grid.GridTableMessage(
             grid.Table,
             wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED,
             0,
             grid.GetNumberCols() - len(v.column_names),
         )
         grid.ProcessTableMessage(tm)
         need_column_layout = True
     elif grid.GetNumberCols() < len(v.column_names):
         tm = wx.grid.GridTableMessage(
             grid.Table,
             wx.grid.GRIDTABLE_NOTIFY_COLS_INSERTED,
             0,
             len(v.column_names) - grid.GetNumberCols(),
         )
         grid.ProcessTableMessage(tm)
         need_column_layout = True
     if len(v.data) < grid.GetNumberRows():
         tm = wx.grid.GridTableMessage(
             grid.Table,
             wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED,
             0,
             grid.GetNumberRows() - len(v.data),
         )
         grid.ProcessTableMessage(tm)
     elif grid.GetNumberRows() < len(v.data):
         tm = wx.grid.GridTableMessage(
             grid.Table,
             wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED,
             0,
             len(v.data) - grid.GetNumberRows(),
         )
         grid.ProcessTableMessage(tm)
     if need_column_layout:
         grid.AutoSizeColumns()
Пример #6
0
 def _get_grid(self, grid):
     """
     given a wxpython Grid objcect, gather all the data, write it out to the ApplicationData objcet and return it.
     """
     data = []
     num_rows = grid.GetNumberRows()
     num_columns = grid.GetNumberCols()
     for row_num in xrange(0, num_rows):
         row = {}
         for column_num in xrange(0, num_columns):
             field_name = grid.GetColLabelValue(column_num)
             value = grid.GetCellValue(row_num, column_num)
             row[field_name] = value
         data.append(row)
     self.application_data.write(mounts=data)
     return data
Пример #7
0
def _invalid_fldname(row, grid):
    "Return boolean and string message"
    other_fldnames = []
    for i in range(grid.GetNumberRows()):
        if i == row:
            continue
        other_fldnames.append(grid.GetCellValue(row=i, col=0))
    field_name = grid.GetCellValue(row=row, col=0)
    if field_name.strip() == '':
        return False, ''
    valid, err = dbe_sqlite.valid_fldname(field_name)
    if not valid:
        msg = _('Field names can only contain letters, numbers, and '
              'underscores.\nOrig error: %s') % err
        return True, msg
    if field_name in other_fldnames:
        msg = _('%s has already been used as a field name') % field_name
        return True, msg
    return False, ''
Пример #8
0
    def reCreateGrid(self, grid=None, row_count=5, col_count=5):
        """
        Re create grid object with new rows and columns

        :param grid: wx.Grid control object.
        :param row_count: Number of row.
        :param col_count: Number of columns.
        :return: True/False.
        """
        if grid is None:
            grid = self._spreadsheet_grid

        if not isinstance(grid, wx.grid.Grid):
            log_func.warning(u'Error grid control type <%s>' %
                             grid.__class__.__name__)
            return False
        try:
            prev_row_count = grid.GetNumberRows()
            prev_col_count = grid.GetNumberCols()
            delta_row_count = row_count - prev_row_count
            delta_col_count = col_count - prev_col_count

            # Clear all data
            grid.ClearGrid()

            if delta_col_count > 0:
                grid.AppendCols(delta_col_count)
            else:
                grid.DeleteCols(prev_col_count + delta_col_count - 1,
                                -delta_col_count)
            if delta_row_count > 0:
                grid.AppendRows(delta_row_count)
            else:
                grid.DeleteRows(prev_row_count + delta_row_count - 1,
                                -delta_row_count)
            # self.Layout()
            return True
        except:
            log_func.fatal(u'Error recreate grid object')
        return False
    def update_selection(self, message=None):
        """Updates the GUI to reflect all the selected positions in the latest parameters.
        If message is set, this is the handler for an external change in selection.
        The message.data dictionary is used instead of latestparams.
        """
        #Re-check the previously checked items.
        if message is None:
            pos_dict = display_thread.get_positions_dict()
        else:
            pos_dict = message.data

        grid = self.panel.gridExp

        all_selected = True
        for i in range(grid.GetNumberRows()):
            #Get the position from the instruments' list.
            if i < len(model.instrument.inst.positions):
                pos = model.instrument.inst.positions[i]
                #Default to False
                this_one_is_selected = pos_dict.get(id(pos), False)
                #Show a space for False.
                val = [" ", "X"][this_one_is_selected]
                #Count if all are selected
                all_selected = all_selected and this_one_is_selected
            else:
                val = "?"
                all_selected = False

            #Check it if you find it, and it's true.
            grid.SetCellValue(i, 0, val)
            grid.SetCellAlignment(i, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)

        #If the selection changes, the estimated time will change too
        self.update_estimated_time()

        #And the "use all" checkbox
        self.inside_set_checkUseAll = True
        self.panel.checkUseAll.SetValue(all_selected)
        self.inside_set_checkUseAll = False
Пример #10
0
    def SaveFile(self, file):
        delimit = '\t'

        grid = self.grid
        col_total = grid.GetNumberCols()
        row_total = grid.GetNumberRows()

        row = 0
        wx.BeginBusyCursor()
        while row < row_total:
            set = []
            col = 0
            while col < col_total:
                value = grid.GetCellValue(row, col)
                set.append(value)
                col += 1
            result = string.joinfields(set, delimit)
            file.write(result)
            file.write('\n')
            row += 1
        file.close()
        wx.EndBusyCursor()
Пример #11
0
    def OnCopy(self, event):
        delimit = '\t'

        grid = self.grid
        col_total = grid.GetNumberCols()
        row_total = grid.GetNumberRows()

        row = 0
        wx.BeginBusyCursor()
        list = []
        while row < row_total:
            set = []
            col = 0
            while col < col_total:
                value = grid.GetCellValue(row, col)
                set.append(value)
                col += 1
            result = string.joinfields(set, delimit)
            list.append(result)
            row += 1
        wx.EndBusyCursor()

        result = string.joinfields(list, '\r')
        self.SetClipboard(result)
Пример #12
0
 def Validate(self, parent):
     grid = self.GetWindow()
     for row_pos in range(grid.GetNumberRows()):
         if grid.GetCellValue(row_pos, 1):
             return True
     return False
Пример #13
0
    def __init__(self, parent, input_para):

        rect_parent = parent.GetRect()
        print rect_parent
        pos_target = rect_parent.GetTopRight()
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          "Resource Grid",
                          pos=pos_target,
                          size=(1000, 700))
        panel = wx.Panel(self, -1)

        sizer_grid = wx.GridBagSizer(0, 0)
        usr_style = wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL
        grid = wx.grid.Grid(self, -1)
        grid.CreateGrid(12 * 2, 14)
        cell_width = 20

        grid.DisableDragColSize()
        grid.DisableDragGridSize()
        grid.DisableDragRowSize()
        grid.SetRowLabelAlignment(wx.CENTER, wx.CENTER)

        clo_num = grid.GetNumberCols()
        row_num = grid.GetNumberRows()

        for i in range(0, row_num):
            grid.SetRowLabelValue(i, str(row_num - i - 1))
            grid.AutoSizeRowLabelSize(i)
        grid.SetRowLabelSize(cell_width)
        grid.SetDefaultRowSize(cell_width)
        for j in range(0, clo_num):
            grid.SetColLabelValue(j, str(j))
            grid.AutoSizeColLabelSize(j)
        grid.SetRowLabelSize(cell_width)
        grid.SetDefaultColSize(cell_width)
        grid.SetDefaultCellBackgroundColour(wx.Colour(192, 192, 192))

        #pdcch
        for i in range(0, row_num):
            for j in range(0, clo_num):
                grid.SetReadOnly(i, j)
                if (j < input_para['pdcch_symbol']):
                    grid.SetCellBackgroundColour(i, j, wx.GREEN)
                    if ((int(grid.GetRowLabelValue(i)) - 1) % 4 == 0):
                        grid.SetCellBackgroundColour(i, j,
                                                     wx.Colour(66, 66, 111))
        #pdsch
        for i in range(0, row_num):
            for j in range(input_para['start_symbol'], clo_num):
                if (j - input_para['start_symbol'] <
                        input_para['symbol_length']):
                    grid.SetCellBackgroundColour(i, j,
                                                 wx.Colour(255, 255, 255))
        #pdsch dmrs
        for j in range(0, len(input_para['dmrs_pos_list'])):
            for i in range(0, row_num):
                if input_para['dmrs_length'] == 0 and j == 0:
                    grid.SetCellBackgroundColour(
                        i, input_para['dmrs_pos_list'][j],
                        wx.Colour(153, 204, 50))
                    continue
                if input_para['dmrs_length'] == 1 and (j == 1 or j == 0):
                    grid.SetCellBackgroundColour(
                        i, input_para['dmrs_pos_list'][j],
                        wx.Colour(153, 204, 50))
                    continue
                else:
                    grid.SetCellBackgroundColour(
                        i, input_para['dmrs_pos_list'][j],
                        wx.Colour(234, 234, 173))

        sizer_grid.Add(grid,
                       pos=(0, 0),
                       span=(5, 5),
                       flag=wx.EXPAND | usr_style)

        lbl_pdcch = wx.StaticText(self, -1, u'  PDCCH  ', style=usr_style)
        lbl_pdcch.SetBackgroundColour(wx.GREEN)
        sizer_grid.Add(lbl_pdcch,
                       pos=(7, 0),
                       span=(1, 1),
                       flag=wx.EXPAND | usr_style)

        lbl_pdcch_dmrs = wx.StaticText(
            self,
            -1,
            u'  PDCCH DMRS  ',
            style=usr_style,
        )
        lbl_pdcch_dmrs.SetBackgroundColour(wx.Colour(66, 66, 111))
        lbl_pdcch_dmrs.SetForegroundColour(wx.Colour(255, 255, 255))
        sizer_grid.Add(
            lbl_pdcch_dmrs,
            pos=(7, 1),
            span=(1, 1),
            flag=wx.EXPAND | usr_style,
        )

        lbl_pdsch = wx.StaticText(self, -1, u'  PDXCH  ', style=usr_style)
        lbl_pdsch.SetBackgroundColour(wx.Colour(255, 255, 255))
        lbl_pdsch.SetForegroundColour(wx.Colour(0, 0, 0))
        sizer_grid.Add(lbl_pdsch,
                       pos=(7, 2),
                       span=(1, 1),
                       flag=wx.EXPAND | usr_style)

        lbl_fl_dmrs = wx.StaticText(self,
                                    -1,
                                    u'Front Loaded DMRS',
                                    style=usr_style)
        lbl_fl_dmrs.SetBackgroundColour(wx.Colour(153, 204, 50))
        lbl_fl_dmrs.SetForegroundColour(wx.Colour(255, 255, 255))
        sizer_grid.Add(lbl_fl_dmrs,
                       pos=(8, 0),
                       span=(1, 1),
                       flag=wx.EXPAND | usr_style)

        lbl_add_dmrs = wx.StaticText(self, -1, u'Add DMRS', style=usr_style)
        lbl_add_dmrs.SetBackgroundColour(wx.Colour(234, 234, 173))
        lbl_add_dmrs.SetForegroundColour(wx.Colour(0, 0, 0))
        sizer_grid.Add(lbl_add_dmrs,
                       pos=(8, 1),
                       span=(1, 1),
                       flag=wx.EXPAND | usr_style)

        b_close = wx.Button(self, -1, "Close")
        self.Bind(wx.EVT_BUTTON, self.close_window, b_close)
        sizer_grid.Add(b_close,
                       pos=(10, 0),
                       span=(2, 5),
                       flag=wx.EXPAND | usr_style)
        self.equal = b_close

        self.SetSizer(sizer_grid)
        sizer_grid.Fit(self)

        self.Show()