Exemplo n.º 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 grid_setup(self):
        """Perform the initial setup and layout of the grid."""
        # @type grid wx.grid.Grid
        grid = self.panel.gridExp
        #General settings
        #grid.SetSelectionMode(wx.grid.Grid.wxGridSelectRows)
        #Label width/height
        grid.SetColLabelSize(40)
        grid.SetRowLabelSize(40)

        #Find that the grid should be
        num_angles = len(model.instrument.inst.angles)
        num_cols = 4 + num_angles
        if grid.GetNumberCols() > num_cols:
            grid.DeleteCols(0, grid.GetNumberCols() - num_cols)
        if grid.GetNumberCols() < num_cols:
            grid.AppendCols(num_cols - grid.GetNumberCols())

        #The column headers
        grid.SetColLabelValue(0, "Use?")
        grid.SetColSize(0, 50)
        #Column # of the criterion
        self.criterion_col = num_angles + 1
        grid.SetColLabelValue(self.criterion_col, "Stopping\nCriterion")
        grid.SetColSize(self.criterion_col, 180)
        grid.SetColLabelValue(self.criterion_col + 1, "Criterion\nValue")
        grid.SetColSize(self.criterion_col + 1, 100)
        grid.SetColLabelValue(self.criterion_col + 2, "Comment")
        grid.SetColSize(self.criterion_col + 2, 120)
        for (i, anginfo) in enumerate(model.instrument.inst.angles):
            grid.SetColLabelValue(
                i + 1, anginfo.name + "\n(" + anginfo.friendly_units + ")")
            grid.SetColSize(i + 1, 100)
Exemplo n.º 3
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
Exemplo n.º 4
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()
 def get_selected_rows(self):
     """Return a list of rows that have been selected, combining
     block and row selections."""
     grid = self.gridExp
     #List of rows
     selection = self.gridExp.GetSelectedRows()
     if len(grid.GetSelectionBlockTopLeft()) > 0:
         #If a block is selected from column 0 to last col (any rows)
         if grid.GetSelectionBlockTopLeft()[0][1] == 0  \
             and grid.GetSelectionBlockBottomRight()[0][1] == grid.GetNumberCols()-1:
             #Add a list of the selected rows (inclusively)
             selection += range(
                 grid.GetSelectionBlockTopLeft()[0][0],
                 grid.GetSelectionBlockBottomRight()[0][0] + 1)
     return selection
Exemplo n.º 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
Exemplo n.º 7
0
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        "Customisation: Draw the data from grid in the rectangle with attributes using the dc."
        dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height)
        try:
            if isSelected:
                fg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
                bg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)
            else:
                fg = attr.GetTextColour()
                bg = attr.GetBackgroundColour()
            dc.SetBrush(wx.Brush(bg, wx.SOLID))
            dc.SetPen(wx.TRANSPARENT_PEN)
            dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)
            if grid.GetGridCursorRow() == row:
                original_pen = dc.GetPen()
                try:
                    border_width = config.row_highlight_width
                    if border_width != 0:
                        if grid.GetParent() is not focused_window():
                            color = config.row_highlight_unfocused_color
                        elif self._table.editing():
                            color = config.row_highlight_edited_color
                        else:
                            color = config.row_highlight_color
                        dc.SetPen(wx.Pen(color, border_width, wx.SOLID))
                        r, mod = divmod(border_width, 2)
                        x, y, width, height = rect
                        left, right, top, bottom = x, x + width, y + r, y + height - r - mod
                        dc.DrawLine(left, top, right, top)
                        dc.DrawLine(left, bottom, right, bottom)
                        if col == 0:
                            dc.DrawLine(left + r + mod, top, left + r + mod,
                                        bottom)
                        if col + 1 == grid.GetNumberCols():
                            dc.DrawLine(right - r - mod, top, right - r - mod,
                                        bottom)

                finally:
                    dc.SetPen(original_pen)
            dc.SetBackgroundMode(wx.TRANSPARENT)
            dc.SetTextForeground(fg)
            dc.SetFont(attr.GetFont())
            self._draw_value(grid.GetCellValue(row, col), dc, rect,
                             attr.GetAlignment()[0])
        finally:
            dc.DestroyClippingRegion()
Exemplo n.º 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
Exemplo n.º 9
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()
Exemplo n.º 10
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)
Exemplo n.º 11
0
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(400, 300))
        #self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.statusbar = self.CreateStatusBar(
        )  # A Statusbar in the bottom of the window

        # Setting up the menu.
        filemenu = wx.Menu()
        # wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWidgets.
        filemenu.Append(wx.ID_ABOUT, "&About",
                        " Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(wx.ID_EXIT, "E&xit", " Terminate the program")

        # Creating the menubar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,
                       "&File")  # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
        panel = wx.Panel(self)

        # Create a wxGrid object
        self.grid = grid = wx.grid.Grid()
        # Then we call CreateGrid to set the dimensions of the grid
        # (100 rows and 10 columns in this example)
        grid.Create(panel)
        grid.CreateGrid(1, 10)
        grid.SetDefaultColSize(50, True)
        grid.SetDefaultRowSize(20, True)

        grid.HideRowLabels()
        grid.EnableGridLines(False)

        grid.AppendRows(grid.GetNumberCols())
        for i in range(1, grid.GetNumberCols()):
            grid.SetColLabelValue(i, "")
        grid.SetColLabelValue(0, "Filename")
        grid.SetColLabelValue(1, "Page")
        grid.SetColLabelValue(2, "New name")
        grid.AutoSizeColumns()

        # Let's lay out the space.  We fill the panel with a vertical sizer so things in it are stcked vertically.
        # Inside that we have a top sizer for small controls and a secon sizer below it for the grid.
        gbs = wx.GridBagSizer(4, 2)

        # The top gridbag row gets buttons
        self.buttonLoad = wx.Button(panel, id=wx.ID_ANY, label="Load")
        gbs.Add(self.buttonLoad, (0, 0))
        self.buttonLoad.Bind(wx.EVT_BUTTON, self.OnLoadButtonClicked)
        self.buttonGenerate = wx.Button(panel, id=wx.ID_ANY, label="Rename")
        gbs.Add(self.buttonGenerate, (0, 1))

        # Now put a pair of buttons with labels above them in the middle two gridbag rows
        gbs.Add(wx.StaticText(panel, label=" Fanzine name"), (1, 0))
        self.fanzineNameTextbox = wx.TextCtrl(panel, id=wx.ID_ANY)
        gbs.Add(self.fanzineNameTextbox, (2, 0))
        self.fanzineNameTextbox.Bind(wx.EVT_TEXT,
                                     self.OnFanzinenameOrIssueTextboxChanged)

        gbs.Add(wx.StaticText(panel, label=" Issue number"), (1, 1))
        self.fanzineIssuenumber = wx.TextCtrl(panel, id=wx.ID_ANY)
        gbs.Add(self.fanzineIssuenumber, (2, 1))
        self.fanzineIssuenumber.Bind(wx.EVT_TEXT,
                                     self.OnFanzinenameOrIssueTextboxChanged)

        # And the grid itself goes in the bottom gridbag row, spanning both columns
        gbs.Add(grid, (3, 0), span=(2, 2))

        panel.SetSizerAndFit(gbs)

        self.Show(True)
Exemplo n.º 12
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()