示例#1
0
    def __init__(self):
        self.numelements = 100
        self.frame = swing.JFrame(windowClosing=self.do_quit)

        # build menu bar
        menubar = swing.JMenuBar()
        file = swing.JMenu("File")
        file.add(swing.JMenuItem("Load", actionPerformed=self.do_load))
        file.add(swing.JMenuItem("Save", actionPerformed=self.do_save))
        file.add(swing.JMenuItem("Quit", actionPerformed=self.do_quit))
        menubar.add(file)
        self.frame.JMenuBar = menubar

        # create widgets
        self.chart = Chart(visible=1)
        self.execentry = swing.JTextArea(default_setup, 8, 60)
        self.evalentry = swing.JTextField(default_expression,
                                          actionPerformed=self.update)

        # create options panel
        optionsPanel = swing.JPanel(
            awt.FlowLayout(alignment=awt.FlowLayout.LEFT))

        # whether the plot is a line graph or a filled graph
        self.filled = swing.JRadioButton("Filled",
                                         actionPerformed=self.set_filled)
        optionsPanel.add(self.filled)
        self.line = swing.JRadioButton("Line", actionPerformed=self.set_line)
        optionsPanel.add(self.line)
        styleGroup = swing.ButtonGroup()
        styleGroup.add(self.filled)
        styleGroup.add(self.line)

        # color selection
        optionsPanel.add(swing.JLabel("Color:", RIGHT))
        colorlist = filter(lambda x: x[0] != '_', dir(colors))
        self.colorname = swing.JComboBox(colorlist)
        self.colorname.itemStateChanged = self.set_color
        optionsPanel.add(self.colorname)

        # number of points
        optionsPanel.add(swing.JLabel("Number of Points:", RIGHT))
        self.sizes = [50, 100, 200, 500]
        self.numpoints = swing.JComboBox(self.sizes)
        self.numpoints.selectedIndex = self.sizes.index(self.numelements)
        self.numpoints.itemStateChanged = self.set_numpoints
        optionsPanel.add(self.numpoints)

        # do the rest of the layout in a GridBag
        self.do_layout(optionsPanel)
示例#2
0
#########################################################################
# implement a simple calculator in Jython; evaluation runs a full 
# expression all at once using the Python eval() built-in--Jython's 
# source-code compiler is present at run-time, as in standard Python
#########################################################################
 
from java import awt                   # get access to Java class libraries
from pawt import swing                 # they look like Python modules here 
     
labels = ['0', '1', '2', '+',          # labels for calculator buttons
          '3', '4', '5', '-',          # will be used for a 4x4 grid
          '6', '7', '8', '*',
          '9', '.', '=', '/' ]
     
keys = swing.JPanel(awt.GridLayout(4, 4))     # do Java class library magic
display = swing.JTextField()                  # Python data auto-mapped to Java
     
def push(event):                              # callback for regular keys
    display.replaceSelection(event.actionCommand)
     
def enter(event):                             # callback for the '=' key
    display.text = str(eval(display.text))    # use Python eval() to run expr
    display.selectAll()
     
for label in labels:                          # build up button widget grid
    key = swing.JButton(label)                # on press, invoke Python funcs
    if label == '=':
        key.actionPerformed = enter
    else:
        key.actionPerformed = push
    keys.add(key)
示例#3
0
#!/jython
from pawt import swing
import sys
from java.awt import Color, BorderLayout


def quit(e):
    sys.exit()


top = swing.JFrame("PySwing")
box = swing.JPanel()
hello = swing.JLabel("hello world")
quit = swing.JButton("QUIT",
                     actionPerformed=quit,
                     background=Color.red,
                     foreground=Color.white)
box.add("North", hello)
box.add("South", quit)
top.contentPane.add(box)
top.pack()
top.visible = 1
示例#4
0
#!/usr/bin/env jython

from pawt import swing
import sys
from java.awt import Color, BorderLayout

def quit(e):
    sys.exit()

top = swing.JFrame("PySwing")
box = swing.JPanel(BorderLayout())
hello = swing.JLabel("Hello World!")
quit = swing.JButton("QUIT", actionPerformed=quit,
    background=Color.red, foreground=Color.white)

box.add("North", hello)
box.add("South", quit)
top.contentPane.add(box)
top.pack()
top.visible = 1	# or True for Jython 2.2+
示例#5
0
    try:
        xBeta[:] = []  #Makes those empty lists so they are ready to hold new
        yBeta[:] = []  #data
        elements[:] = []
        setUp()
        plot.removeAllGraphData()  #To get rid of previous plots
        plotAns()
        filler.removeAll()  #Removes previous table
        makeTable()  #Adds the new table
    except ValueError:
        error.text = "Make sure all of the magnet displays are displaying numbers before plotting."


#Putting stuff on panels-----------------------------------------------------

buttons = swing.JPanel(awt.GridLayout(3, 2, 1, 10))

for label in labels:  #Adding most of the buttons
    key = swing.JButton(label)
    if label == 'clear x':
        key.actionPerformed = clrx
    if label == 'clear y':
        key.actionPerformed = clry
    if label == 'clear results':
        key.actionPerformed = clrr
    if label == 'clear all':
        key.actionPerformed = clra
    if label == 'clear energy':
        key.actionPerformed = clre
    if label == 'calculate':
        key.actionPerformed = calc