| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
from wxSkinLayoutObject import wxSkinLayoutObject, wxColorEval, wxSkinObjectNoData |
|---|
| 27 |
from wxPython.grid import * |
|---|
| 28 |
from wxPython.wx import * |
|---|
| 29 |
|
|---|
| 30 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 31 |
#~ Class |
|---|
| 32 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 33 |
|
|---|
| 34 |
class grid(wxSkinLayoutObject, wxSkinObjectNoData): |
|---|
| 35 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 36 |
#~ Constants / Variables / Etc. |
|---|
| 37 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 38 |
|
|---|
| 39 |
default_settings = wxSkinLayoutObject.default_settings.copy() |
|---|
| 40 |
default_settings.update({ |
|---|
| 41 |
'name': __name__, |
|---|
| 42 |
'wxid': 'wxNewId()', |
|---|
| 43 |
'custom': '0', |
|---|
| 44 |
'lines': '1', |
|---|
| 45 |
'editable': '1', |
|---|
| 46 |
'margins': '0,0', |
|---|
| 47 |
'selectmode':'cells', |
|---|
| 48 |
'dragsize': 'all', |
|---|
| 49 |
'autosize': 'all', |
|---|
| 50 |
'columns': "['A','B','C','D','E']", |
|---|
| 51 |
'rows': "['1','2','3','4','5']", |
|---|
| 52 |
'rowlabelsize': '', |
|---|
| 53 |
'collabelsize': '', |
|---|
| 54 |
'fgselection': 0, |
|---|
| 55 |
'bgselection': 0, |
|---|
| 56 |
}) |
|---|
| 57 |
|
|---|
| 58 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 59 |
#~ Public |
|---|
| 60 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 61 |
|
|---|
| 62 |
def SkinInitialize(self): |
|---|
| 63 |
winParent = self.wxGetParentObject(wx.wxWindowPtr) |
|---|
| 64 |
kwSettings = self.wxSettingDict(['wxid', 'style', 'pos', 'size'], ['name']) |
|---|
| 65 |
self.object = wxGrid(winParent, **kwSettings) |
|---|
| 66 |
self.object.BeginBatch() |
|---|
| 67 |
self.wxInitialStandardOptions() |
|---|
| 68 |
|
|---|
| 69 |
def SkinFinalize(self): |
|---|
| 70 |
self.wxFinalStandardOptions() |
|---|
| 71 |
|
|---|
| 72 |
if not self.wxEval('custom'): |
|---|
| 73 |
cols = self.wxEval('columns') |
|---|
| 74 |
if isinstance(cols, int): cols = map(chr, xrange(65, 65+cols)) |
|---|
| 75 |
colcount = len(cols) |
|---|
| 76 |
|
|---|
| 77 |
rows = self.wxEval('rows') |
|---|
| 78 |
if isinstance(rows, int): rows = map(str, xrange(1, 1+rows)) |
|---|
| 79 |
rowcount = len(rows) |
|---|
| 80 |
|
|---|
| 81 |
if rowcount or colcount: |
|---|
| 82 |
self.object.CreateGrid(rowcount, colcount) |
|---|
| 83 |
|
|---|
| 84 |
idx = 0 |
|---|
| 85 |
for each in cols: |
|---|
| 86 |
if isinstance(each, tuple): self.object.SetColLabelValue(idx, *each) |
|---|
| 87 |
else: self.object.SetColLabelValue(idx, each) |
|---|
| 88 |
idx += 1 |
|---|
| 89 |
idx = 0 |
|---|
| 90 |
for each in rows: |
|---|
| 91 |
if isinstance(each, tuple): self.object.SetRowLabelValue(idx, *each) |
|---|
| 92 |
else: self.object.SetRowLabelValue(idx, each) |
|---|
| 93 |
idx += 1 |
|---|
| 94 |
|
|---|
| 95 |
# Misc Options |
|---|
| 96 |
self.object.EnableEditing(self.wxEval('editable')) |
|---|
| 97 |
self.object.EnableGridLines(self.wxEval('lines')) |
|---|
| 98 |
self.object.SetMargins(*self.wxEval('margins')) |
|---|
| 99 |
|
|---|
| 100 |
if self.settings['fgselection']: |
|---|
| 101 |
self.object.SetSelectionForeground(wxColorEval(self.settings['fgselection'])) |
|---|
| 102 |
if self.settings['bgselection']: |
|---|
| 103 |
self.object.SetSelectionBackground(wxColorEval(self.settings['bgselection'])) |
|---|
| 104 |
|
|---|
| 105 |
# Row and Column Labels |
|---|
| 106 |
if self.settings['rowlabelsize']: |
|---|
| 107 |
self.object.SetRowLabelSize(self.wxEval('rowlabelsize')) |
|---|
| 108 |
if self.settings['collabelsize']: |
|---|
| 109 |
self.object.SetColLabelSize(self.wxEval('collabelsize')) |
|---|
| 110 |
|
|---|
| 111 |
# Autosize |
|---|
| 112 |
autosize = self.settings['autosize'].lower() |
|---|
| 113 |
if autosize == 'all': |
|---|
| 114 |
self.object.AutoSizeRows() |
|---|
| 115 |
self.object.AutoSizeColumns() |
|---|
| 116 |
elif autosize == 'rows': |
|---|
| 117 |
self.object.AutoSizeRows() |
|---|
| 118 |
elif autosize == 'columns': |
|---|
| 119 |
self.object.AutoSizeColumns() |
|---|
| 120 |
|
|---|
| 121 |
# Draw Size |
|---|
| 122 |
dragsize = self.settings['dragsize'].lower() |
|---|
| 123 |
if dragsize == 'all': |
|---|
| 124 |
self.object.EnableDragGridSize(1) |
|---|
| 125 |
elif dragsize == 'rows': |
|---|
| 126 |
self.object.EnableDragRowSize(1) |
|---|
| 127 |
self.object.EnableDragColSize(0) |
|---|
| 128 |
elif dragsize == 'columns': |
|---|
| 129 |
self.object.EnableDragRowSize(0) |
|---|
| 130 |
self.object.EnableDragColSize(1) |
|---|
| 131 |
elif dragsize == 'none': |
|---|
| 132 |
self.object.EnableDragGridSize(0) |
|---|
| 133 |
|
|---|
| 134 |
# Selection Mode |
|---|
| 135 |
selectmode = self.settings['selectmode'].lower() |
|---|
| 136 |
if selectmode == 'cells': |
|---|
| 137 |
self.object.SetSelectionMode(self.object.wxGridSelectCells) |
|---|
| 138 |
elif selectmode == 'rows': |
|---|
| 139 |
self.object.SetSelectionMode(self.object.wxGridSelectRows) |
|---|
| 140 |
elif selectmode == 'columns': |
|---|
| 141 |
self.object.SetSelectionMode(self.object.wxGridSelectColumns) |
|---|
| 142 |
|
|---|
| 143 |
self.object.EndBatch() |
|---|