refactored code to decouple object construction from initializaion

This commit is contained in:
Arkady Trestman 2010-05-13 22:16:45 +00:00
parent b9de3daa41
commit efb320b74c
6 changed files with 18 additions and 10 deletions

View File

@ -27,9 +27,17 @@ class LevelEditor(LevelEditorBase):
self.objectHandler = ObjectHandler(self) self.objectHandler = ObjectHandler(self)
self.protoPalette = ProtoPalette() self.protoPalette = ProtoPalette()
# LevelEditorUI class must declared after ObjectPalette # Populating uderlined data-structures
self.ui = LevelEditorUI(self) self.ui = LevelEditorUI(self)
self.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
self.objectPalette.populate()
self.protoPalette.populate()
# Updating UI-panels based on the above data
self.ui.objectPaletteUI.populate()
self.ui.protoPaletteUI.populate()
# When you define your own LevelEditor class inheriting LevelEditorBase # When you define your own LevelEditor class inheriting LevelEditorBase
# you should call self.initialize() at the end of __init__() function # you should call self.initialize() at the end of __init__() function
self.initialize() self.initialize()
self.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))

View File

@ -40,7 +40,7 @@ class ObjectPaletteBase:
self.data = {} self.data = {}
self.dataStruct = {} self.dataStruct = {}
self.dataKeys = [] self.dataKeys = []
self.populate() #self.populate()
def insertItem(self, item, parentName): def insertItem(self, item, parentName):
""" """

View File

@ -13,8 +13,6 @@ class ObjectPaletteUI(wx.Panel):
self.palette = self.editor.objectPalette self.palette = self.editor.objectPalette
self.tree = PaletteTreeCtrl(self, treeStyle=wx.TR_DEFAULT_STYLE, rootName='Objects') self.tree = PaletteTreeCtrl(self, treeStyle=wx.TR_DEFAULT_STYLE, rootName='Objects')
self.dataKeys = self.palette.dataKeys[:]
self.tree.addTreeNodes(self.tree.GetRootItem(), self.palette.rootName, self.palette.dataStruct, self.dataKeys)
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.tree, 1, wx.EXPAND, 0) sizer.Add(self.tree, 1, wx.EXPAND, 0)
@ -40,6 +38,9 @@ class ObjectPaletteUI(wx.Panel):
self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelected) self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelected)
def populate(self):
self.tree.addTreeNodes(self.tree.GetRootItem(), self.palette.rootName, self.palette.dataStruct, self.palette.dataKeys)
def onSelected(self, event): def onSelected(self, event):
pass pass

View File

@ -36,7 +36,6 @@ class PaletteTreeCtrl(wx.TreeCtrl):
def addTreeNodes(self, parentItem, parentItemName, items, itemKeys): def addTreeNodes(self, parentItem, parentItemName, items, itemKeys):
roots = [] roots = []
rootItems = [] rootItems = []
#import pdb;set_trace()
for key in itemKeys: for key in itemKeys:
if parentItemName == items[key]: if parentItemName == items[key]:
roots.append(key) roots.append(key)

View File

@ -71,7 +71,6 @@ class ProtoObjsUI(wx.Panel):
self.Bind(wx.EVT_CONTEXT_MENU, self.onShowPopup) self.Bind(wx.EVT_CONTEXT_MENU, self.onShowPopup)
self.SetDropTarget(ProtoDropTarget(self)) self.SetDropTarget(ProtoDropTarget(self))
self.populate()
def populate(self): def populate(self):
for key in self.protoObjs.data.keys(): for key in self.protoObjs.data.keys():

View File

@ -48,9 +48,6 @@ class ProtoPaletteUI(wx.Panel):
self.palette = self.editor.protoPalette self.palette = self.editor.protoPalette
self.tree = PaletteTreeCtrl(self, treeStyle=wx.TR_EDIT_LABELS|wx.TR_DEFAULT_STYLE, rootName="Proto Objects") self.tree = PaletteTreeCtrl(self, treeStyle=wx.TR_EDIT_LABELS|wx.TR_DEFAULT_STYLE, rootName="Proto Objects")
self.dataKeys = self.palette.dataStruct.keys()[:]
self.tree.addTreeNodes(self.tree.GetRootItem(), self.palette.rootName, self.palette.dataStruct, self.dataKeys)
self.editorTxt = "Proto Objects Editor" self.editorTxt = "Proto Objects Editor"
self.opSortAlpha = "Sort Alphabetical Order" self.opSortAlpha = "Sort Alphabetical Order"
@ -91,6 +88,10 @@ class ProtoPaletteUI(wx.Panel):
self.SetDropTarget(UniversalDropTarget(self.editor)) self.SetDropTarget(UniversalDropTarget(self.editor))
def populate(self):
dataStructKeys = self.palette.dataStruct.keys()[:]
self.tree.addTreeNodes(self.tree.GetRootItem(), self.palette.rootName, self.palette.dataStruct, dataStructKeys)
def OnBeginLabelEdit(self, event): def OnBeginLabelEdit(self, event):
self.editor.ui.bindKeyEvents(False) self.editor.ui.bindKeyEvents(False)