Esempio n. 1
0
    def OnKey(self, event):
        """Handles non-standard shortcut events"""

        keycode = event.GetKeyCode()

        # If in selection mode and <Enter> is pressed end it
        if not self.grid.IsEditable() and keycode == 13:
            ## TODO!
            pass

        elif event.ControlDown():
            if keycode == 388:
                # Ctrl + + pressed
                post_command_event(self.grid, self.grid.ZoomInMsg)

            elif keycode == 390:
                # Ctrl + - pressed
                post_command_event(self.grid, self.grid.ZoomOutMsg)

            elif keycode == 13:
            # <Ctrl> + <Enter>
                grid = self.grid
                grid.DisableCellEditControl()

                row = self.grid.GetGridCursorRow()
                col = self.grid.GetGridCursorCol()
                tab = grid.current_table
                key = row, col, tab

                val = grid.code_array(key)
                grid.actions.set_code(key, '"' + val + '"')

                grid.MoveCursorDown(False)

        else:
            # No Ctrl pressed

            if keycode == 127:
                # Del pressed

                # Delete cell at cursor
                cursor = self.grid.actions.cursor
                self.grid.actions.delete_cell(cursor)

                # Delete selection
                self.grid.actions.delete_selection()

                # Update grid
                self.grid.ForceRefresh()

                # Do not enter cell
                return

            elif keycode == 27:
                # Esc pressed
                self.grid.actions.need_abort = True

        event.Skip()
Esempio n. 2
0
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        """Draws the cell border and content using pycairo"""

        key = row, col, grid.current_table

        # If cell is merge draw the merging cell if invisibile
        if grid.code_array.cell_attributes[key]["merge_area"]:
            key = self.get_merging_cell(grid, key)

        drawn_rect = self._get_drawn_rect(grid, key, rect)
        if drawn_rect is None:
            return

        cell_cache_key = self._get_draw_cache_key(grid, key, drawn_rect,
                                                  isSelected)

        mdc = wx.MemoryDC()

        if vlc is not None and key in self.video_cells and \
           grid.code_array.cell_attributes[key]["panel_cell"]:
            # Update video position of previously created video panel
            self.video_cells[key].SetClientRect(drawn_rect)

        elif cell_cache_key in self.cell_cache:
            mdc.SelectObject(self.cell_cache[cell_cache_key])

        else:
            code = grid.code_array(key)
            if vlc is not None and code is not None and \
               grid.code_array.cell_attributes[key]["panel_cell"]:
                try:
                    # A panel is to be displayed
                    panel_cls = grid.code_array[key]

                    # Assert that we have a subclass of a wxPanel that we
                    # can instantiate
                    assert issubclass(panel_cls, wx.Panel)

                    video_panel = panel_cls(grid)
                    video_panel.SetClientRect(drawn_rect)
                    # Register video cell
                    self.video_cells[key] = video_panel

                    return

                except Exception, err:
                    # Someting is wrong with the panel to be displayed
                    post_command_event(grid.main_window,
                                       self.StatusBarMsg,
                                       text=unicode(err))
                    bmp = self._get_cairo_bmp(mdc, key, drawn_rect, isSelected,
                                              grid._view_frozen)
            else:
Esempio n. 3
0
    def _get_draw_cache_key(self, grid, key, drawn_rect, is_selected):
        """Returns key for the screen draw cache"""

        row, col, tab = key
        cell_attributes = grid.code_array.cell_attributes

        zoomed_width = drawn_rect.width / self.zoom
        zoomed_height = drawn_rect.height / self.zoom

        # Button cells shall not be executed for preview
        if grid.code_array.cell_attributes[key]["button_cell"]:
            cell_preview = repr(grid.code_array(key))[:100]
            __id = id(grid.code_array(key))
        else:
            cell_preview = repr(grid.code_array[key])[:100]
            __id = id(grid.code_array[key])

        sorted_keys = sorted(grid.code_array.cell_attributes[key].iteritems())

        key_above_left = row - 1, col - 1, tab
        key_above = row - 1, col, tab
        key_above_right = row - 1, col + 1, tab
        key_left = row, col - 1, tab
        key_right = row, col + 1, tab
        key_below_left = row + 1, col - 1, tab
        key_below = row + 1, col, tab

        borders = []

        for k in [
                key, key_above_left, key_above, key_above_right, key_left,
                key_right, key_below_left, key_below
        ]:
            borders.append(cell_attributes[k]["borderwidth_bottom"])
            borders.append(cell_attributes[k]["borderwidth_right"])
            borders.append(cell_attributes[k]["bordercolor_bottom"])
            borders.append(cell_attributes[k]["bordercolor_right"])

        return (zoomed_width, zoomed_height, is_selected, cell_preview, __id,
                tuple(sorted_keys), tuple(borders))
Esempio n. 4
0
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        """Draws the cell border and content using pycairo"""

        key = row, col, grid.current_table

        # If cell is merge draw the merging cell if invisibile
        if grid.code_array.cell_attributes[key]["merge_area"]:
            key = self.get_merging_cell(grid, key)

        drawn_rect = self._get_drawn_rect(grid, key, rect)
        if drawn_rect is None:
            return

        cell_cache_key = self._get_draw_cache_key(grid, key, drawn_rect,
                                                  isSelected)

        mdc = wx.MemoryDC()

        if vlc is not None and key in self.video_cells and \
           grid.code_array.cell_attributes[key]["panel_cell"]:
            # Update video position of previously created video panel
            self.video_cells[key].SetClientRect(drawn_rect)

        elif cell_cache_key in self.cell_cache:
            mdc.SelectObject(self.cell_cache[cell_cache_key])

        else:
            code = grid.code_array(key)
            if vlc is not None and code is not None and \
               grid.code_array.cell_attributes[key]["panel_cell"]:
                try:
                    # A panel is to be displayed
                    panel_cls = grid.code_array[key]

                    # Assert that we have a subclass of a wxPanel that we
                    # can instantiate
                    assert issubclass(panel_cls, wx.Panel)

                    video_panel = panel_cls(grid)
                    video_panel.SetClientRect(drawn_rect)
                    # Register video cell
                    self.video_cells[key] = video_panel

                    return

                except Exception, err:
                    # Someting is wrong with the panel to be displayed
                    post_command_event(grid.main_window, self.StatusBarMsg,
                                       text=unicode(err))
                    bmp = self._get_cairo_bmp(mdc, key, drawn_rect, isSelected,
                                              grid._view_frozen)
            else:
Esempio n. 5
0
    def _get_draw_cache_key(self, grid, key, drawn_rect, is_selected):
        """Returns key for the screen draw cache"""

        row, col, tab = key
        cell_attributes = grid.code_array.cell_attributes

        zoomed_width = drawn_rect.width / self.zoom
        zoomed_height = drawn_rect.height / self.zoom

        # Button cells shall not be executed for preview
        if grid.code_array.cell_attributes[key]["button_cell"]:
            cell_preview = repr(grid.code_array(key))[:100]
            __id = id(grid.code_array(key))
        else:
            cell_preview = repr(grid.code_array[key])[:100]
            __id = id(grid.code_array[key])

        sorted_keys = sorted(grid.code_array.cell_attributes[key].iteritems())

        key_above_left = row - 1, col - 1, tab
        key_above = row - 1, col, tab
        key_above_right = row - 1, col + 1, tab
        key_left = row, col - 1, tab
        key_right = row, col + 1, tab
        key_below_left = row + 1, col - 1, tab
        key_below = row + 1, col, tab

        borders = []

        for k in [key, key_above_left, key_above, key_above_right,
                  key_left, key_right, key_below_left, key_below]:
            borders.append(cell_attributes[k]["borderwidth_bottom"])
            borders.append(cell_attributes[k]["borderwidth_right"])
            borders.append(cell_attributes[k]["bordercolor_bottom"])
            borders.append(cell_attributes[k]["bordercolor_right"])

        return (zoomed_width, zoomed_height, is_selected, cell_preview, __id,
                tuple(sorted_keys), tuple(borders))