Exemple #1
0
    def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell, visible_cells):
        model = grid_control.model
        first_col = self.cell_to_col[first_cell]
        last_cell = min(first_cell + visible_cells, self.num_cells)
        last_col = self.cell_to_col[last_cell - 1] + 1
        last_row = min(first_row + visible_rows, model.antic_lines)
        drawlog.debug("draw_grid: rows:%d,%d, cols:%d,%d" % (first_row, last_row, first_col, last_col))

        ul_rect = self.col_to_rect(first_row, first_col)
        lr_rect = self.col_to_rect(last_row - 1, last_col - 1)
        frame_rect = wx.Rect(ul_rect.x, ul_rect.y, lr_rect.x - ul_rect.x + lr_rect.width, lr_rect.y - ul_rect.y + lr_rect.height)

        bytes_per_row = model.items_per_row
        first_index = first_row * bytes_per_row
        last_index = last_row * bytes_per_row
        data = model.data[first_index:last_index]
        style = model.style[first_index:last_index]
        drawlog.debug("draw_grid: first_index:%d last_index:%d" % (first_index, last_index))

        array = grid_control.bitmap_renderer.get_image(grid_control.segment_viewer, bytes_per_row, last_row - first_row, last_index - first_index, data, style)
        width = array.shape[1]
        height = array.shape[0]
        drawlog.debug("Calculated image: %dx%d" % (width, height))
        if width > 0 and height > 0:
            # image returned will have the correct number of rows but will be
            # 160 pixels wide; need to crop to visible columns
            cropped = array[:,first_col:last_col,:]
            array = intscale(cropped, grid_control.zoom_h, grid_control.zoom_w)
            #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape)))
            image = wx.Image(array.shape[1], array.shape[0])
            image.SetData(array.tostring())
            bmp = wx.Bitmap(image)
            dc.SetClippingRegion(frame_rect)
            dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)
Exemple #2
0
    def prepare_image(self):
        """Creates new image at specified zoom factor.

        Creates a new image that is to be used as the background of
        the scrolled bitmap.  Currently, actually creates the entire
        image, which could lead to memory problems if the image is
        really huge and the zoom factor is large.
        """
        if self.is_ready_to_render():
            self.calc_image_size()

            w, h = self.GetClientSize().Get()
            dc = wx.MemoryDC()
            self.scaled_bmp = wx.Bitmap(w, h)

            dc.SelectObject(self.scaled_bmp)
            dc.SetBackground(
                wx.Brush(self.segment_viewer.preferences.empty_color))
            dc.Clear()

            array = self.get_image()
            width = array.shape[1]
            height = array.shape[0]
            if width > 0 and height > 0:
                zw, zh = self.get_zoom_factors()
                array = intscale(array, zh, zw)
                self.draw_overlay(array, width, height, zw, zh)
                image = wx.Image(array.shape[1], array.shape[0])
                image.SetData(array.tostring())
                bmp = wx.Bitmap(image)
                dc.DrawBitmap(bmp, 0, 0)
Exemple #3
0
    def get_full_image(self, segment=None):
        if segment is None:
            segment = self.segment
        log.debug("get_full_image: fontmap: start=%d, num=%d" %
                  (self.start_row, self.visible_rows))
        sr = 0
        nr = self.total_rows
        start_byte = 0
        end_byte = self.total_rows * self.bytes_per_row
        if end_byte > len(segment):
            end_byte = len(segment)
            bytes = np.zeros((nr * self.bytes_per_row), dtype=np.uint8)
            bytes[0:end_byte -
                  start_byte] = segment[sr * self.bytes_per_row:end_byte]
            style = np.zeros((nr * self.bytes_per_row), dtype=np.uint8)
            style[0:end_byte -
                  start_byte] = segment.style[sr *
                                              self.bytes_per_row:self.end_byte]
        else:
            bytes = segment[start_byte:end_byte].copy()
            style = segment.style[start_byte:end_byte].copy()
        # turn off any selections
        style &= get_style_mask(selected=True)

        bytes = bytes.reshape((nr, -1))
        style = style.reshape((nr, -1))
        #log.debug("get_image: bytes", bytes)

        v = self.segment_viewer
        font = v.get_blinking_font(0)
        array = v.machine.font_renderer.get_image(v, font, bytes, style,
                                                  start_byte, end_byte,
                                                  self.bytes_per_row, nr, 0,
                                                  self.bytes_per_row)
        if self.font.scale_h > 1 or self.font.scale_w > 1:
            array = intscale(array, self.font.scale_h, self.font.scale_w)
        if self.zoom > 1:
            array = intscale(array, self.zoom)
        return array
Exemple #4
0
 def draw_item(self, grid_control, dc, rect, data, style):
     start = 0
     end = len(data)
     nr = 1
     array = grid_control.bitmap_renderer.get_image(
         grid_control.segment_viewer, end, nr, end, data, style)
     width = array.shape[1]
     height = array.shape[0]
     if width > 0 and height > 0:
         array = intscale(array, grid_control.zoom_h, grid_control.zoom_w)
         #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape)))
         image = wx.Image(array.shape[1], array.shape[0])
         image.SetData(array.tostring())
         bmp = wx.Bitmap(image)
         dc.DrawBitmap(bmp, rect.x, rect.y)
Exemple #5
0
 def draw_item(self, parent, dc, rect, data, style):
     start = 0
     end = len(data)
     nr = 1
     data = data.reshape((nr, -1))
     style = style.reshape((nr, -1))
     v = parent.segment_viewer
     array = parent.font_renderer.get_image(v, v.current_antic_font, data, style, start, end, end, nr, start, end)
     width = array.shape[1]
     height = array.shape[0]
     if width > 0 and height > 0:
         array = intscale(array, parent.zoom_h, parent.zoom_w)
         image = wx.Image(array.shape[1], array.shape[0])
         image.SetData(array.tostring())
         bmp = wx.Bitmap(image)
         dc.DrawBitmap(bmp, rect.x, rect.y)
Exemple #6
0
    def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell,
                  visible_cells):
        t = grid_control.table
        first_col = self.cell_to_col[first_cell]
        last_cell = min(first_cell + visible_cells, self.num_cells)
        last_col = self.cell_to_col[last_cell - 1] + 1
        last_row = min(first_row + visible_rows, t.num_rows)
        log.debug("draw_grid: rows:%d,%d (vis %d, num %d) cols:%d,%d" %
                  (first_row, last_row, visible_rows, t.num_rows, first_col,
                   last_col))

        ul_rect = self.col_to_rect(first_row, first_col)
        lr_rect = self.col_to_rect(last_row - 1, last_col - 1)
        frame_rect = wx.Rect(ul_rect.x, ul_rect.y,
                             lr_rect.x - ul_rect.x + lr_rect.width,
                             lr_rect.y - ul_rect.y + lr_rect.height)
        dc.SetClippingRegion(frame_rect)

        # First and last rows may not span entire width. Process those
        # separately
        #
        # First row may not have bytes at the beginning of the row if the start
        # offset is not zero
        if first_row == 0:
            try:
                col, index, last_index = self.calc_column_range(
                    grid_control, first_row, first_col, last_col)
            except IndexError:
                pass  # skip lines with no visible cells
            else:
                self.draw_line(grid_control, dc, first_row, col, index,
                               last_index)
            first_row += 1
            if first_row == last_row:
                return
            frame_rect.y += ul_rect.height

        # Last row may not have bytes at the end of the row
        if last_row == t.num_rows:
            try:
                col, index, last_index = self.calc_column_range(
                    grid_control, last_row - 1, first_col, last_col)
            except IndexError:
                pass  # skip lines with no visible cells
            else:
                self.draw_line(grid_control, dc, last_row - 1, col, index,
                               last_index)
            last_row -= 1

        bytes_per_row = t.items_per_row
        nr = last_row - first_row
        nc = last_col - first_col
        first_index = (first_row * bytes_per_row) - t.start_offset
        last_index = (last_row * bytes_per_row) - t.start_offset
        t = t
        if last_index > len(t.data):
            last_index = len(t.data)
            data = np.zeros((nr * bytes_per_row), dtype=np.uint8)
            data[0:last_index - first_index] = t.data[first_index:last_index]
            style = np.zeros((nr * bytes_per_row), dtype=np.uint8)
            style[0:last_index - first_index] = t.style[first_index:last_index]
        else:
            data = t.data[first_index:last_index]
            style = t.style[first_index:last_index]

        # get_image(cls, machine, antic_font, bytes, style, start_byte, end_byte, bytes_per_row, nr, start_col, visible_cols):

        array = grid_control.bitmap_renderer.get_image(
            grid_control.segment_viewer, bytes_per_row, nr, bytes_per_row * nr,
            data, style)
        width = array.shape[1]
        height = array.shape[0]
        if width > 0 and height > 0:
            array = intscale(array, grid_control.zoom_h, grid_control.zoom_w)
            #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape)))
            image = wx.Image(array.shape[1], array.shape[0])
            image.SetData(array.tostring())
            bmp = wx.Bitmap(image)
            dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)