| 1 |
# -*- coding: utf-8 -*- |
|---|
| 2 |
import dabo |
|---|
| 3 |
from dabo.dLocalize import _ |
|---|
| 4 |
import dabo.dEvents as dEvents |
|---|
| 5 |
if __name__ == "__main__": |
|---|
| 6 |
dabo.ui.loadUI("wx") |
|---|
| 7 |
dui = dabo.ui |
|---|
| 8 |
from ClassDesignerComponents import LayoutPanel |
|---|
| 9 |
from ClassDesignerComponents import LayoutBasePanel |
|---|
| 10 |
from ClassDesignerComponents import LayoutSpacerPanel |
|---|
| 11 |
from ClassDesignerComponents import LayoutSizer |
|---|
| 12 |
from ClassDesignerComponents import LayoutBorderSizer |
|---|
| 13 |
from ClassDesignerComponents import LayoutGridSizer |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
class ObjectPropertySheet(dui.dPanel): |
|---|
| 17 |
def afterInit(self): |
|---|
| 18 |
self.app = self.Application |
|---|
| 19 |
self.propGrid = grd = dui.dGrid(self) |
|---|
| 20 |
self.propGrid.bindEvent(dEvents.MouseLeftDoubleClick, self.onEdit) |
|---|
| 21 |
sz = self.Sizer = dui.dSizer("v") |
|---|
| 22 |
sz.append1x(self.propGrid) |
|---|
| 23 |
col = dui.dColumn(grd, Caption=_("Property Name"), Order=10, |
|---|
| 24 |
DataField="propName", DataType=str, Name="PropName", |
|---|
| 25 |
Width=100, Sortable=True) |
|---|
| 26 |
grd.addColumn(col) |
|---|
| 27 |
col = dui.dColumn(grd, Caption=_("Default Value"), Order=20, |
|---|
| 28 |
DataField="defaultValue", Name="DefaultValue", |
|---|
| 29 |
Width=80, Sortable=False) |
|---|
| 30 |
grd.addColumn(col) |
|---|
| 31 |
col = dui.dColumn(grd, Caption=_("Comment"), Order=30, |
|---|
| 32 |
DataField="comment", DataType=str, Name="Comment", |
|---|
| 33 |
Width=200, Sortable=False) |
|---|
| 34 |
grd.addColumn(col) |
|---|
| 35 |
col = dui.dColumn(grd, Caption=_("Get"), Order=40, |
|---|
| 36 |
DataField="getter", DataType=bool, Name="Get", Width=40, |
|---|
| 37 |
Sortable=False) |
|---|
| 38 |
grd.addColumn(col) |
|---|
| 39 |
col = dui.dColumn(grd, Caption=_("Set"), Order=50, |
|---|
| 40 |
DataField="setter", DataType=bool, Name="Set", Width=40, |
|---|
| 41 |
Sortable=False) |
|---|
| 42 |
grd.addColumn(col) |
|---|
| 43 |
col = dui.dColumn(grd, Caption=_("Del"), Order=60, |
|---|
| 44 |
DataField="deller", DataType=bool, Name="Del", Width=40, |
|---|
| 45 |
Sortable=False) |
|---|
| 46 |
grd.addColumn(col) |
|---|
| 47 |
|
|---|
| 48 |
self.addButton = dui.dButton(self, Caption=_("Add")) |
|---|
| 49 |
self.addButton.bindEvent(dEvents.Hit, self.onAdd) |
|---|
| 50 |
self.editButton = dui.dButton(self, Caption=_("Edit")) |
|---|
| 51 |
self.editButton.bindEvent(dEvents.Hit, self.onEdit) |
|---|
| 52 |
self.delButton = dui.dButton(self, Caption=_("Delete")) |
|---|
| 53 |
self.delButton.bindEvent(dEvents.Hit, self.onDelete) |
|---|
| 54 |
hsz = dui.dSizer("H") |
|---|
| 55 |
hsz.append(self.addButton) |
|---|
| 56 |
hsz.appendSpacer(12) |
|---|
| 57 |
hsz.append(self.editButton) |
|---|
| 58 |
hsz.appendSpacer(12) |
|---|
| 59 |
hsz.append(self.delButton) |
|---|
| 60 |
sz.append(hsz, border=10) |
|---|
| 61 |
self.populatePropList() |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
def onAdd(self, evt): |
|---|
| 65 |
"""Add a custom property to the object.""" |
|---|
| 66 |
self.app.editObjectProperty(None) |
|---|
| 67 |
self.populatePropList() |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
def onEdit(self, evt): |
|---|
| 71 |
currProp = self.propGrid.getValue(col=0) |
|---|
| 72 |
self.app.editObjectProperty(currProp) |
|---|
| 73 |
self.populatePropList() |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
def onDelete(self, evt): |
|---|
| 77 |
currProp = self.propGrid.getValue(col=0) |
|---|
| 78 |
self.app.deleteObjectProperty(currProp) |
|---|
| 79 |
self.populatePropList() |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
def select(self, obj): |
|---|
| 83 |
"""Called when the selected object changes.""" |
|---|
| 84 |
if isinstance(obj, (list, tuple)): |
|---|
| 85 |
if len(obj) == 0: |
|---|
| 86 |
return |
|---|
| 87 |
else: |
|---|
| 88 |
obj = obj[0] |
|---|
| 89 |
self.addButton.Enabled = self.editButton.Enabled = \ |
|---|
| 90 |
self.delButton.Enabled = not isinstance(obj, |
|---|
| 91 |
(LayoutPanel, LayoutBasePanel, LayoutSpacerPanel, LayoutSizer, |
|---|
| 92 |
LayoutBorderSizer, LayoutGridSizer)) |
|---|
| 93 |
self.populatePropList() |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
def populatePropList(self): |
|---|
| 97 |
"""Fill the grid with the custom Properties for the selected object.""" |
|---|
| 98 |
sel = self.app._selection |
|---|
| 99 |
if len(sel) == 0: |
|---|
| 100 |
# Nothing there yet! |
|---|
| 101 |
return |
|---|
| 102 |
elif len(sel) > 1: |
|---|
| 103 |
pd = {} |
|---|
| 104 |
else: |
|---|
| 105 |
obj = self.app._selection[0] |
|---|
| 106 |
pd = self.app._classPropDict.get(obj, {}) |
|---|
| 107 |
props = pd.keys() |
|---|
| 108 |
data = [] |
|---|
| 109 |
for prop in props: |
|---|
| 110 |
data.append(pd[prop]) |
|---|
| 111 |
self.propGrid.DataSet = data |
|---|
| 112 |
self.propGrid.fillGrid(True) |
|---|
| 113 |
self.editButton.Enabled = self.delButton.Enabled = (len(props) > 0) |
|---|