示例#1
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()
示例#2
0
    def commitChanges(self):
        try:
            grid = self.GetView()
            pos = grid.GetGridCursorRow()
            if (pos >= 0):
                lastGridLabel = self.om.reqs[pos].label()
                if (len(str(lastGridLabel).split('-')) > 1):
                    l_str_errorText = [
                        'Asset or Environment must be specified.'
                    ]
                    if self.om.reqs[pos].attrs['asset'] != '':
                        l_str_errorText.append(
                            '\n\nRecommended asset filter: ')
                        l_str_errorText.append(
                            self.om.reqs[pos].attrs['asset'])

                    errorText = ''.join(l_str_errorText)
                    raise ARMException(errorText)
            self.om.commitChanges()
        except ARMException, errorText:
            dlg = wx.MessageDialog(self.GetView(), errorText.value,
                                   'Commit changes', wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return
示例#3
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]
示例#4
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)
示例#5
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)
示例#6
0
 def GetAttr(self, rowIndex, columnIndex, kind = 0):
     grid = self.GetView()
     if grid is None or not grid.customCellAttributes \
             or rowIndex >= len(self.rowHandles) \
             or columnIndex >= len(self.columns):
         return super(GridTable, self).GetAttr(rowIndex, columnIndex, kind)
     column = self.columns[columnIndex]
     attr = column.attr.Clone()
     if grid.highlightRowColor is not None \
             and rowIndex == grid.GetGridCursorRow():
         attr.SetBackgroundColour(grid.highlightRowColor)
     handle = self.rowHandles[rowIndex]
     row = self.dataSet.rows[handle]
     grid.OnGetCustomCellAttributes(row, column, attr)
     return attr
示例#7
0
文件: _grid.py 项目: nicLucian/pytis
    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()
示例#8
0
文件: igrid.py 项目: yumei165/ipython
 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")
示例#9
0
文件: igrid.py 项目: yumei165/ipython
 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")
示例#10
0
    def Draw(self, grid, dc, rect, row):
        graphicUtils.DrawLineGradient(dc, rect.GetX(), rect.GetY(),
                                      rect.GetX() + rect.GetWidth() - 2,
                                      rect.GetY() + rect.GetHeight() - 1,
                                      self._start_color, self._end_color)
        r = wx.Rect(rect.GetX(), rect.GetY(), rect.GetWidth(),
                    rect.GetHeight())
        if self._drawNumRow:
            hAlign, vAlign = grid.GetRowLabelAlignment()
            text = grid.GetRowLabelValue(row)
            dc.SetPen(wx.TRANSPARENT_PEN)
            self.DrawText(grid, dc, rect, text, hAlign, vAlign)

        # Top Line
        dc.SetPen(self._top_pen)
        dc.DrawLine(r.GetX(), r.GetY(), r.GetX() + r.GetWidth(), r.GetY())
        dc.DrawLine(r.GetX(),
                    r.GetY() + 1,
                    r.GetX() + r.GetWidth(),
                    r.GetY() + 1)
        # Right Line
        dc.SetPen(self._right_pen)
        dc.DrawLine(r.GetX() + r.GetWidth() - 1, r.GetY(),
                    r.GetX() + r.GetWidth() - 1,
                    r.GetY() + r.GetHeight())
        # Left Line
        dc.SetPen(self._left_pen)
        dc.DrawLine(r.GetX(), r.GetY(), r.GetX(), r.GetY() + r.GetHeight())
        # Bottom
        dc.SetPen(self._bot_pen)
        dc.DrawLine(r.GetX(),
                    r.GetY() + r.GetHeight() - 1,
                    r.GetX() + r.GetWidth(),
                    r.GetY() + r.GetHeight() - 1)

        if self.IsDrawCursor() and grid.GetGridCursorRow() == row:
            st = 0
            sty = r.GetY()
            penBound = wx.Pen(SORT_BORDER_CLR)
            dc.SetPen(penBound)
            brush = wx.Brush(SORT_P_CLR, wx.SOLID)
            dc.SetBrush(brush)
            dc.DrawPolygon(CursorMarkDark, mark_shith_x + st,
                           mark_shith_y + sty)
示例#11
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()