[TransWarp] first experiences with Transwarp
ML
lists at net-labs.de
Tue Mar 26 20:05:48 EST 2002
=====
For some reason, this post from Ulrich didn't make it through to the list...
=====
Hi Phillip,
> I would advise holding off for a bit on digging too deep into the use of
> Elements and Features, however, as I'm about to redo their API
> entirely. After that's done, it should be possible to make some simple
.. <snip>
i watch your progress with Element/Features ... looks promising :)
I have worked on a concept for the GUI with Transwarp .. this is my
way to evaluate Transwarp for our project ..
precondition is that one uses wxWindows and the new XML-Resource-system.
I have come up with a similar system to RecordManager->RecordType:
all Gui-Objects derive from baseclass GUIObject(SEF.Base) that has a class-init
method that finds it Child-Objects (only classes/instances of
GUIObject-Interface)
and stores it in newClass.guiObjects.
a <root-class>.setup() method set's up the whole GUI-Object-Tree recursivly.
by invoking <child>.setup(). this is actually needed because i make heavy
use of
SEF-Bindings that don't exist at __init__ and some wxPython issues.
I created BaseClasses for Window,Panel,Control,Event,Menu,... and some
specializations.
Most of them are Services.
a Menu-Specification would look like:
-----------------------------------------------------------------------------
from TW.API import *
from wxPython.wx import *
from EMF.GUI.Menu import MenuBar,Menu,MenuItem
from EMF.GUI.Event import connectEvent
class MainMenu(MenuBar):
_xmlid = 'menuMain'
class Console(Menu):
_xmlid = 'mnuConsole'
class Save(MenuItem):
_xmlid = 'mnuConsoleSave'
OnConsoleSave = connectEvent(EVT_MENU)
class Exit(MenuItem):
_xmlid = 'mnuConsoleExit'
def OnConsoleExitHandler(self,event):
self.getService('AppWindow')._close_window()
return 1
OnConsoleExit = connectEvent(EVT_MENU,func=OnConsoleExitHandler)
setupModule()
-----------------------------------------------------------------------------
Notes:
- MenuBar,Menu,MenuItem are Services
- _xmlid Attribute allways specifies the XMLID of the Resource
- connectEvent is a specialization of Once that creates an Event-Connector
to the given
wxEvent and the EventDispatcher (one can specify a custom func via
func=<method> param)
- If a GUIObject contains anothers, these are it's child-objects (e.g.
MenuBar has Menus, these
have MenuItems ...):
a Panel-Specification would look like:
-----------------------------------------------------------------------------
from TW.API import *
from EMF.GUI.Basic import *
from EMF.GUI import Event
from EMF.GUI.Panel import SplitWindow,Panel
from EMF.GUI.Control import TextControl,TreeControl,Button
from EMF.GUI.Event import connectEvent
class MainPanel(SplitWindow):
class EventDispatcher(Event.EventDispatcher):
def _dispatch(self,name,obj,event,category):
if category in ['Control','Panel']:
self.log.debug(self,"handling event: %s" % name)
return 1 # do not dispatch ...
class TreePanel(Panel):
_xmlid = 'panelMainTree'
class treeMain(TreeControl):
_xmlid = 'treeControl'
def _setup_control(self):
##### this should come from DataLayer
self.treeRoot = self.WX.AddRoot('someTest')
self.WX.SetPyData(self.treeRoot,None)
self.WX.SelectItem(self.treeRoot)
self.WX.AppendItem(self.treeRoot,'test1',4,-1,wxTreeItemData('test'))
self.WX.AppendItem(self.treeRoot,'test2',4,-1,wxTreeItemData('test'))
self.WX.AppendItem(self.treeRoot,'test3',4,-1,wxTreeItemData('test'))
self.WX.AppendItem(self.treeRoot,'test4',4,-1,wxTreeItemData('test'))
class ListPanel(Panel):
_xmlid = 'panelDialogNBFirst'
class txtFirst(TextControl):
_xmlid = 'txtFirst'
class txtSecond(TextControl):
_xmlid = 'txtSecond'
class txtThird(TextControl):
_xmlid = 'txtThird'
class btOK(Button):
_xmlid = 'btOK'
class btCancel(Button):
_xmlid = 'btCancel'
setupModule()
-----------------------------------------------------------------------------
Notes:
- the BaseClasses have an EventLayer mixed in, that provides a standard set of
pre-connected Events for the Controls/Buttons/Panels
e.g. ListControl has OnListItemSelected/... predefined.
- I expect an "EventDispatcher" that is a placefull service defined
somewhere in your
app, that handles all Events for it's domain or forward it to an
EventDispatcher
up in the Tree.
- There is an ordering problem .. which Panel will be first in
newClass.__dict__.items() ?
i will probably use the attribute guiObjects =['TreePanel','ListPanel']
to fix this.
a MainWindow example:
-----------------------------------------------------------------------------
from TW.API import *
from EMF.GUI.Basic import *
from EMF.GUI.Window import MainWindow,loadResource
class AppWindow(MainWindow):
Resources = loadResource('emfgui_wdr.xrc')
from MyMenu import MainMenu
from MyPanels import MainPanel
from EMF.GUI.Event import EventDispatcher
setupModule()
-----------------------------------------------------------------------------
Notes:
- loadResource is again a specialization of Once that loads the XML-Resource
- Only import all the defined components and a write a
simple Main app:
-----------------------------------------------------------------------------
from TW.API import *
from EMF.GUI.Basic import *
from EMF.GUI.App import App
class TestApp(App):
from Main import AppWindow
# replace App._init_app
def _init_app(self,parent):
super(TestApp,self)._init_app(parent)
self.log.debug(self,'_init_app')
self.AppWindow.setup()
return true
def __init__():
if __name__=='__main__':
app = TestApp()
app.setup('TestApp')
app.run()
setupModule()
-----------------------------------------------------------------------------
.. that's it .. ;-)
this is quite a bit code for the first example .. but i find it necessary
to make the
concept a bit clearer.
i have attached a sample output from my logger-module (that i extended a bit to
print out the inheritance-tree of the objects .. somewhat the "url" of the
object)
after coming that far .. I'ld like to hear your comment.
it is working with latest cvs-checkouts of TW and wxPython-2.3.2 on win and
linux ..
i can provide the sources of the lib if anyone is interested in this early
stage ...
i build the framework without use of the (Data)Elements and Features ..
because as
far as i understand they are provided by the specialists of my Application.
right now there is no connection between the controls and the features of
an Element and i have not yet found a satisfying solution for this problem.
Do you have a hint, how I could "link" the setter/getter - methods of my
control
with an Elements-Feature somewhere up in the object-tree: make use of an
"Element" Service that provides the current Element or some better idea??
then you would be able to map the controls-values to the Elements features
and most of standard-typing would be gone :)
what do you think ??
Ulrich Eck
ueck at net-labs.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: debug.log
Type: application/octet-stream
Size: 13619 bytes
Desc: not available
Url : http://www.eby-sarna.com/pipermail/peak/attachments/20020326/a7ec63e3/debug.obj
More information about the PEAK
mailing list