Re: Help with firing an event from a button

[email protected]
Newsgroups gmane.comp.gnu.enterprise.general
Message-ID <[email protected]>
Hello.

El jue, mar 25, a las 07:59:46 James Thompson escribía:
> 
> ...
> 
> On Wednesday 24 March 2004 08:10 pm, [email protected] wrote:
> > First Question. Is this a good approach ?
> >
> > Second: Why can't I find the form object with findParentOfType()? should
> > I walk up myself thru the tree to find it?
> >
> 
> ...
> 
> When you write a trigger in forms you have access to all the named objects 
> you've defined in your gfd file, plus a few extra items.  So lets look at 
> samples/zipcode/zipcode.gfd for a moment
> 
> In there we have the following piece of code
> 
>     <block name="zip" datasource="zips" rows="15">
>       <field name="city" case="upper" field="city" required="Y">
> 
> You'll notice both those objects have names.  The block is named "zip" the 
> field is named "city".  These names are available to you as a trigger 
> programmer.  Lets say I want to have a button that prints the value in the 
> record to the console.  Any one of the following 3 lines in your trigger code 
> would work
> 
> print zip.city
> print "%s" % zip.city
> print zip.city.get()
> 
> ...
> 
> to the nature of the namespace system it is possible to get odd results at 
> times.  I'll refrain from going into those details in this mail.  If someone 
> really wants to know why let me know and I'll give more detail.  However it 
> is  a level of detail not important to trigger writers.
> 
> You'll notice that in the examples above I treated zip.city as a text field, I 
> also called functions against it.  Objects in the namespace have various 
> functions defined against them.  I just took a look at the Forms Developers 
> Guide (http://www.gnuenterprise.org/tools/forms/) and see while there is some 
> data starting at page 26 it is very incomplete.  And thus doesn't list these 
> functions :(  One more thing for the todo.  
> 
> Lets get the code you needed now.
> > ## Perform list page up
> > # form =  self.findParentOfType('GFForm')
> > # if form != None:
> > #   form.dispatchEvent('JUMPROWSUP');
> 
> If I understand what youre trying to do below you want the trigger to move 
> thru the currently loaded records in memory.  
> 
> If you want to tell a block to move backward 1 record.
> zip.prevRecord()
> 
> forward 1.
> zip.nextRecord()
> 
> Note: If you have a form with multiple rows displayed, then when you click on 
> your button focus will change to the button.  That is why you won't see 
> cursor doesn't jump to the next record.  But the record counter in the lower 
> right will reflect the change, and if you hit <tab> to shift focus off the 
> button it will be in the new record.
> 
> Since these functions do not seem to be documented I'll pass on a trick to 
> finding them.  You are welcome to ask here too of course as the rest of this 
> deals with gnue-forms and gnue-common internals.
> 
> Almost every tag in the gfd format maps to a single .py file in the gnue-forms 
> source.  The key files are gnue-forms/src/GFForm.py, and all those in 
> gnue-forms/src/GFObjects/*.py.  We're going to have to go in here to find 
> those functions.  But this isn't as bad as it seems.  We know that "zip" is 
> the name of our block,  gnue-forms/src/GFObjects/GFBlock.py contains the 
> internal representation of that <block> tag.  By looking in there we find a 
> python dictionary named self._triggerFunctions.  If you look at it's 
> definition you'll find the following entries. (pardon the line wrap)
> 
> 'nextRecord':{'function':self.nextRecord,
>                          'description':'Navigates the block to the next record 
> in sequence.'},
> 'prevRecord':{'function':self.prevRecord,
>                          'description':'Navigates the block to the previous 
> record in sequence.'},
> 
> This is how gnue-common lets someone extend the trigger namespace.  
> 
> 'exposedName' : { internalDefinition }
> 
> The exposedName as that is what you will use in the trigger.  So we have
> 
> objectName.exposedName or in the example above zip.prevRecord()
> 
> One thing worth mentioning about the internalDefinition.  If you happen to 
> notice that it contains 'global': True  then this function is part of the 
> global trigger namespace.  Basically you can treat it as a part of the 
> trigger language built in functions.  An example of this is in GFForm.py
> 
> 'showMessage':{'function':self.triggerShowMessageBox,
>                                              'global': True,
>                                              },
> 
> In any trigger in our form we can put
> 
> showMessage("Hi there!")
> 
> ...
> 
> I hope this helps.
> 

Sure it will.

Relating to your explanation, I can use my block/@name, but I've tried
to use form/@name as global ( I have: <form name="myForm">; then, I try:
myForm.showMessage('...') ) and got this:

Traceback:
  Trigger "unknown_executioncontext" (unknown), line 25
      name 'myForm' is not defined
exceptions.NameError: ("name 'myForm' is not defined",)

if, instead, I do: form.showMessage('...'), it works fine, so it isn't
critical ;).

But, for now, and just becuase I've been, as you suggest, looking at
forms code, I found, at GFInstance.py, events labeled JUMPROWSDOWN
and JUMPROWSUP. I also found shift-PgDn/PgUp instructed for listening
to them at GFKeyMapper, but not so any toolbar button.

What I'd like is having a button with that functionality, as toolbar has
for next/previous/first/last records.

I've been looking at GFBlock, and found that with block methods, I'll
have to do a loop for '@rows' number or so. How can I get block/@rows
value?

In the other way, I suppose it should be possible to fire JUMPROWSXXX
events that would do the job. I've tried form.dispatchEvent() also,
but I got an Exception saying dispatchEvent was an unknown attribute,
thought it's a method from GFForm.

And I've looking for a way to customize toolbar and found defined at
ToolBar.py. I'm new to python, but I've seen, at documentation,
that yo can derive a new class with same that parent: could I do that
with ToolBar, redefining _DEFAULT_TOOLBAR and loading derived class via
ImportPath to get a customized toolbar?

thanks in advance
-- 
José Esteban
Granada - Spain
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.