|
From: John H. <ec...@ya...> - 2013-03-21 05:01:02
|
Haven't done this for a while. It's basically something like this (untested):
import wx
import new
from PythonCard import log
from PythonCard import model, dialog
"""
This is how to invoke:
Control_factory(self, attribute={"type":"Button", "name":"Button1",
"label":"Button1","position":(5,35)},
eventHandlers={"mouseClick":on_Button_mouseClick})
def on_Button_mouseClick(self, event):
return
"""
class Control_factory():
def addHandler(self, aMethod):
# Add the Handler to our Handler list.
try:
_handlers=self._handlers
except:
self._handlers={}
if aMethod.name not in self._handlers:
log.debug("addHandler: " + aMethod.name)
#self._handlers[aMethod.name] = event.Handler(aMethod)
self._handlers[aMethod.name] = aMethod
def delHandler(self, aMethod):
# Add the Handler to our Handler list.
if aMethod.name in self._handlers:
log.debug("delHandler: " + aMethod.name)
del self._handlers[aMethod.name]
del aMethod
def __init__(self, parent, attribute, eventHandlers):
name=attribute['name']
self.methods=[]
for eventName in eventHandlers.keys():
eventFct=eventHandlers[eventName]
def function(parent, background, event):
if eventFct==None:
return None
return eventFct(event)
function.name = "on_%s_%s" % (name,eventName)
method = new.instancemethod(function, parent, parent.__class__)
setattr(parent, function.name, method)
self.addHandler(method)
self.methods.append(method)
parent.components[name] = attribute
return
def getMethods(self):
return self.methods
Control_factory(self, attribute={"type":"ImageButton", "name":"stop",
"position":(10,10), 'border':'transparent', 'command':u'stop','file':'',
'visible':False, }, eventHandlers={"mouseClick":on_stop_mouseClick})
On 9/27/2012 11:35 PM, Alec Bennett wrote:
Hello very quiet Pythoncard email list!
>
>
>I'm trying to add an ImageButton dynamically to a resource file, and can't
>figure out how to do so.
>
>
>Suppose the ImageButton looked like this:
>
>
>{'type':'ImageButton',
> 'name':'stop',
> 'position':(10, 10),
> 'border':'transparent',
> 'command':u'stop',
> 'file':'',
> 'visible':False,
> },
>
>
>And I refer to the components in this resource file like this:
>
>
>self.childWindow.components.whateverButton.visible = False (etc.)
>
>
>Any idea how I would add this ImageButton component, short of writing to the
>actual resource file?
>
>
>Thanks for any help.
>
>
>
>
>
>
>
>
>
>
>
>
>------------------------------------------------------------------------------
>Got visibility? Most devs has no idea what their production app looks like. Find
>out how fast your code is with AppDynamics Lite.
>http://ad.doubleclick.net/clk;262219671;13503038;y?
>http://info.appdynamics.com/FreeJavaPerformanceDownload.html
>
>
>_______________________________________________ Pythoncard-users mailing list
>Pyt...@li...
>https://lists.sourceforge.net/lists/listinfo/pythoncard-users
>
--
John Henry
|