Exemple #1
0
def getGridSelectedCells(grid):
    """
    Return the selected cells in the grid as a list of
    (row, col) pairs.
    We need to take care of three possibilities:
    1. Multiple cells were click-selected (GetSelectedCells)
    2. Multiple cells were drag selected (GetSelectionBlock...)
    3. A single cell only is selected (CursorRow/Col)
    """

    top_left = grid.GetSelectionBlockTopLeft()

    if top_left:
        bottom_right = grid.GetSelectionBlockBottomRight()
        return [
            grid.GetCellValue(x[0], x[1])
            for x in corners_to_cells(top_left, bottom_right)
        ]

    selection = grid.GetSelectedCells()

    if not selection:
        row = grid.GetGridCursorRow()
        col = grid.GetGridCursorCol()
        return [grid.GetCellValue(row, col)]

    return [grid.GetCellValue(x[0], x[1]) for x in selection]
Exemple #2
0
    def OnKey(self, event):
        """Handles non-standard shortcut events"""

        grid = self.grid
        actions = grid.actions

        shift, alt, ctrl = 1, 1 << 1, 1 << 2

        # Shortcuts key tuple: (modifier, keycode)
        # Modifier may be e. g. shift | ctrl

        shortcuts = {
            # <Esc> pressed
            (0, 27):
            lambda: setattr(actions, "need_abort", True),
            # <Del> pressed
            (0, 127):
            actions.delete,
            # <Home> pressed
            (0, 313):
            lambda: actions.set_cursor((grid.GetGridCursorRow(), 0)),
            # <Ctrl> + R pressed
            (ctrl, 82):
            actions.copy_selection_access_string,
            # <Ctrl> + + pressed
            (ctrl, 388):
            actions.zoom_in,
            # <Ctrl> + - pressed
            (ctrl, 390):
            actions.zoom_out,
            # <Shift> + <Space> pressed
            (shift, 32):
            lambda: grid.SelectRow(grid.GetGridCursorRow()),
            # <Ctrl> + <Space> pressed
            (ctrl, 32):
            lambda: grid.SelectCol(grid.GetGridCursorCol()),
            # <Shift> + <Ctrl> + <Space> pressed
            (shift | ctrl, 32):
            grid.SelectAll,
        }

        keycode = event.GetKeyCode()
        #print keycode

        modifier = shift * event.ShiftDown() | \
            alt * event.AltDown() | ctrl * event.ControlDown()

        if (modifier, keycode) in shortcuts:
            shortcuts[(modifier, keycode)]()

        else:
            event.Skip()
Exemple #3
0
 def find_next(self, event):
     """
     find the next occurrence
     """
     if self.searchtext:
         grid = self.notebook.GetPage(self.notebook.GetSelection()).grid
         row = grid.GetGridCursorRow()
         col = grid.GetGridCursorCol()
         if col+1 < grid.table.GetNumberCols():
             grid.search(self.searchtext, row, col+1)
         else:
             grid.search(self.searchtext, row+1, 0)
     else:
         self.enter_searchtext(event)
Exemple #4
0
 def find_previous(self, event):
     """
     find previous occurrences
     """
     if self.searchtext:
         grid = self.notebook.GetPage(self.notebook.GetSelection()).grid
         row = grid.GetGridCursorRow()
         col = grid.GetGridCursorCol()
         if col-1 >= 0:
             grid.search(self.searchtext, row, col-1, False)
         else:
             grid.search(self.searchtext, row-1, grid.table.GetNumberCols()-1, False)
     else:
         self.enter_searchtext(event)
Exemple #5
0
 def find_previous(self, event):
     """
     find previous occurrences
     """
     grid = self.notebook.GetPage(self.notebook.GetSelection()).grid
     if self.searchtext:
         row = grid.GetGridCursorRow()
         col = grid.GetGridCursorCol()
         self.SetStatusText('Search mode: text; looking for %s' % self.searchtext)
         if col-1 >= 0:
             grid.search(self.searchtext, row, col-1, False)
         else:
             grid.search(self.searchtext, row-1, grid.table.GetNumberCols()-1, False)
     elif self.searchexpression:
         self.SetStatusText("Search mode: expression; looking for %s" % repr(self.searchexpression)[2:-1])
         grid.searchexpression(searchexp=self.searchexpression, search_forward=False)
     else:
         self.SetStatusText("No search yet: please enter search-text or -expression")
Exemple #6
0
 def find_next(self, event):
     """
     find the next occurrence
     """
     grid = self.notebook.GetPage(self.notebook.GetSelection()).grid
     if self.searchtext != "":
         row = grid.GetGridCursorRow()
         col = grid.GetGridCursorCol()
         self.SetStatusText('Search mode: text; looking for %s' % self.searchtext)
         if col+1 < grid.table.GetNumberCols():
             grid.search(self.searchtext, row, col+1)
         else:
             grid.search(self.searchtext, row+1, 0)
     elif self.searchexpression != "":
         self.SetStatusText('Search mode: expression; looking for %s' % repr(self.searchexpression)[2:-1])
         grid.searchexpression(searchexp=self.searchexpression)
     else:
         self.SetStatusText("No search yet: please enter search-text or -expression")
Exemple #7
0
    def OnKey(self, event):
        """Handles non-standard shortcut events"""
        def switch_to_next_table():
            newtable = self.grid.current_table + 1
            post_command_event(self.grid,
                               self.GridActionTableSwitchMsg,
                               newtable=newtable)

        def switch_to_previous_table():
            newtable = self.grid.current_table - 1
            post_command_event(self.grid,
                               self.GridActionTableSwitchMsg,
                               newtable=newtable)

        grid = self.grid
        actions = grid.actions

        shift, alt, ctrl = 1, 1 << 1, 1 << 2

        # Shortcuts key tuple: (modifier, keycode)
        # Modifier may be e. g. shift | ctrl

        shortcuts = {
            # <Esc> pressed
            (0, 27):
            lambda: setattr(actions, "need_abort", True),
            # <Del> pressed
            (0, 127):
            actions.delete,
            # <Home> pressed
            (0, 313):
            lambda: actions.set_cursor((grid.GetGridCursorRow(), 0)),
            # <Ctrl> + R pressed
            (ctrl, 82):
            actions.copy_selection_access_string,
            # <Ctrl> + + pressed
            (ctrl, 388):
            actions.zoom_in,
            # <Ctrl> + - pressed
            (ctrl, 390):
            actions.zoom_out,
            # <Shift> + <Space> pressed
            (shift, 32):
            lambda: grid.SelectRow(grid.GetGridCursorRow()),
            # <Ctrl> + <Space> pressed
            (ctrl, 32):
            lambda: grid.SelectCol(grid.GetGridCursorCol()),
            # <Shift> + <Ctrl> + <Space> pressed
            (shift | ctrl, 32):
            grid.SelectAll,
        }

        if self.main_window.IsFullScreen():
            # <Arrow up> pressed
            shortcuts[(0, 315)] = switch_to_previous_table
            # <Arrow down> pressed
            shortcuts[(0, 317)] = switch_to_next_table
            # <Space> pressed
            shortcuts[(0, 32)] = switch_to_next_table

        keycode = event.GetKeyCode()

        modifier = shift * event.ShiftDown() | \
            alt * event.AltDown() | ctrl * event.ControlDown()

        if (modifier, keycode) in shortcuts:
            shortcuts[(modifier, keycode)]()

        else:
            event.Skip()