apr 6
status ?
So ... how far along are you?
Jython? Eclipse? Project? Hg?
-----------------------------------
Sam
Aaron
Ian
Peter
Devin
Elias
Hg - Mercurial
I've managed to get a google code repo which
can be tied to an eclipse project.
New google code repo :
Part of assignment for next time: add a new file to this repository, misc/yourname.txt
Eclipse notes
Trying to type import lines can still cause
my system to freeze when it tries to do name completion
with many, many options. Sigh. Type "from java.awt import Font"
in another editor and paste it in? Yeah, *that's* why GUI's make
life easier.
Another gripe about pydev + jython in Eclipse :
# This is marked as an error the GUI, even though it isn't.
class AppFrame(JFrame):
def __init__(self):
JFrame.__init__(self, ...) # pydev marks this as an error
...
The error is "undefined variable from import: __init__".
I expect the issue is that by convention "__" things are private
and not export in python. Therefore, the GUI isn't aware that
JFrame has an __init__ method. But of course it does, and
calling the parent's method in this way is a very common practice.
java gui docs
Mouse events :
... says mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased are all possible "interesting" mouse events for an AWT component; any could be treated in that way, eh?
Graphics API :
The AWT Graphics class for drawing lines, images, text, ...
Layout mangers :
Frame:
- frame.setSize(w,h) ; frame.setLocation(x,y)
- frame.repaint(self.visibleRect) # mark as "dirty" after change so it gets redrawn
in class
(1) Add a button to marlboro-jython-gui that modifies the 'Hi there.' text.
(2) Display an image in the window.
(3) Have the image move somewhere in response to some sort of event.
See
That last one shows how to get clicks at a fairly low level; I think it could be used to look inside the "event" type and do interesting things.
from javax.swing import JPanel
class Foo(JPanel):
def __init__(self):
self.mousePressed = self.pressed
def pressed(self, event):
print "mouse clicked"
# ... look inside event to figure out where
Apr 6 gui version
from java.awt import Font, BorderLayout, Color
from javax.swing import JFrame, JPanel, JButton
from random import random
class AppFrame(JFrame):
def __init__(self):
JFrame.__init__(self, 'Jython GUI App',
size = (256, 128),
defaultCloseOperation = JFrame.EXIT_ON_CLOSE)
self.message = MessagePanel()
self.add(self.message)
self.button = JButton("Change text", actionPerformed=self.change)
self.add(self.button, BorderLayout.SOUTH)
self.visible = True
def change(self, event):
self.message.text = 'Changed text!'
self.background = Color(random(), random(), random())
self.repaint()
class MessagePanel(JPanel):
def __init__(self):
self.text = 'Hi there.'
def paintComponent(self, graphics):
graphics.font = Font('Arial', Font.PLAIN, 32)
graphics.drawString(self.text, 32, 64)
if __name__ == '__main__':
app = AppFrame()
book