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()
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
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]
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)
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)
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
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()
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")
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")
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)
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()