Hi it apears that event is getting converted into a string.
Redhat tends to come with gcj and gnu classpath on the path. You
might not be using the jdk.
On 20-Dec-06, at 10:46 PM, David Marshall wrote:
> leouser:
>
> You didn't mention what Linux platform you are using.
> I can get this working on Windows but not on Linux Red Hat 3.4 with
> Java 1.5/Jython 2.1 I tried your variation and get the same error:
> AttributeError 'string' object has no attribute 'source' I should
> mention that the swing GUI I've built (JFrame,JTextFields, JLabels,
> JButtons etc) works perfectly until I add the line of code that
> tries to get an event.source in my action handler
>
> b = javax.swing.JButton("hi")
> b.actionPerformed=self.handleAction
>
> def handleAction (self, event):
> print event # works fine. Prints out the java.awt.event.ActionEvent
> # print event.source # causes the Attribute error if I uncomment
> this line
>
> When I run the above I get a printout like >>>
> java.awt.event.ActionEvent
> [ACTION_PERFORMED,cmd=A,when=1166630615069,modifiers=Button1] on
> javax.swing.JButton[,181,5,43x25,alignmentX=0.0,alignmentY=0.5,
> border=javax.swing.plaf.BorderUIResource
> $CompoundBorderUIResource@...
> referredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=
> javax.swing.plaf.InsetsUIResource
> [top=2,left=14,bottom=2,right=14 ],paintBorder=true,paintFocus=true,pr
> essedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,se
> lectedIcon=,text=A,defaultCapable=true]
>
> So the event object getting passed to the method looks right. I
> can't understand why jython gripes about handleAction at the time I
> try to instantiate my gui object. Clearly its got the java
> libraries it needs since its passing the ActionEvent. Why does it
> think event is a string?
>
> I tried adding import java.awt.event.ActionEvent but that didn't help
>
> Does this look like I've got some kind of subtle configuration
> problem or is Jython just buggy depending on the platform? I
> haven't used jython for more than 1 day but these mixed results are
> making me think its not a solid cross-platform language.
>
> --- Message: 2 Date: Tue, 19 Dec 2006 11:40:47 -0800 (PST) From:
> Leo User <leouser126@...> Subject: Re: [Jython-users] Jython
> on Linux not dealing with swing Event class To: jython-
> users@... Message-ID:
> <20061219194047.2842.qmail@...> Content-
> Type: text/plain; charset=iso-8859-1 This code works for me:
>
>>>> >>> import javax.swing as sw
>>>> >>> jb = sw.JButton("CATSSSS")
>>>> >>> def zoo(act):
>>>>
> ... print act
> ... print act.source
> ... print act.source.text
> ...
>
>>>> >>> jb.actionPerformed = zoo
>>>> >>> jb.doClick()
>>>>
> java.awt.event.ActionEvent
> [ACTION_PERFORMED,cmd=CATSSSS,when=1166557263790,modifiers=]
> on
> javax.swing.JButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,
> border=javax.swing.plaf.BorderUIResource
> $CompoundBorderUIResource@...=,
> preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin
> =javax.swing.plaf.InsetsUIResource
> [top=2,left=14,bottom=2,right=14 ],paintBorder=true,paintFocus=true,pr
> essedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,se
> lectedIcon=,text=CATSSSS,defaultCapable=true]
> javax.swing.JButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,
> border=javax.swing.plaf.BorderUIResource
> $CompoundBorderUIResource@...=,
> preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin
> =javax.swing.plaf.InsetsUIResource
> [top=2,left=14,bottom=2,right=14 ],paintBorder=true,paintFocus=true,pr
> essedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,se
> lectedIcon=,text=CATSSSS,defaultCapable=true]
> CATSSSS
>
> how about for you?
> leouser
>
>
> --- David Marshall <marshall62@...> wrote:
>
>
>> > I'm having some problems with Jython and Swing on a
>> > Linux (CentOS = RedHat
>> > 3.2) box
>> > > If I have some Jython code like:
>> > > class MyGui(javax.swing.JFrame):
>> > > def buildGUI (self):
>> > b =
>> > javax.swing.JButton("Hi",actionPerformed=self.sayHi)
>> > ... other code to add button to panel etc
>> > > def sayHi (self, event):
>> > print event.source.text
>> > > When I try to create a instance of MyGui
>> > g = MyGui()
>> > > I get a stack trace with:
>> > > Attribute Error: 'string' has no attribute 'source'
>> > > It doesn't like that print event.source.text
>> > statement.
>> > > The same code works correctly on Windows Jython.
>> > > This code is very similar to a calculator GUI that
>> > is in the O'Reilly
>> > "Essential Python" book so its pretty standard
>> > stuff. Makes me worry that
>> > Linux Jython isn't ready for prime time.
>> > > Any ideas/help?
>> > > > I've got the latest JDKs and Jythons installed
>> > > thanks
>>
>
>
>
> --
> David Marshall
> http://www.cs.umass.edu/~marshall
> ----------------------------------------------------------------------
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to
> share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?
> page=join.php&p=sourceforge&CID=DEVDEV________________________________
> _______________
> Jython-users mailing list
> Jython-users@...
> https://lists.sourceforge.net/lists/listinfo/jython-users
|