Exemplo n.º 1
0
def view_image(image):
    # create a frame/window
    frame = swing.JFrame("Jython Image Viewer")
    #allows frame corner x to exit properly
    frame.defaultCloseOperation = swing.JFrame.EXIT_ON_CLOSE
    frame.visible = True
    #change to fit image size
    frame.setSize(1500, 1000)
    frame.getContentPane().add(swing.JLabel(swing.ImageIcon(image)))
    frame.show()
Exemplo n.º 2
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)
Exemplo n.º 3
0
def view(url):
    frame = swing.JFrame("Image: " + url, visible=1)
    frame.getContentPane().add(swing.JLabel(swing.ImageIcon(net.URL(url))))
    frame.setSize(400,250)
    frame.show()
Exemplo n.º 4
0
"""\
Equivalent to the ../awt/simple.py example but using swing components
instead of AWT ones.
"""

# This line will import the appropriate swing library for your system (jdk 1.1 or 1.2)
from pawt import swing
import java


def exit(e):
    java.lang.System.exit(0)


frame = swing.JFrame('Swing Example', visible=1)
button = swing.JButton('Close Me!', actionPerformed=exit)
frame.contentPane.add(button)
frame.pack()
Exemplo n.º 5
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
Exemplo n.º 6
0
  if value is not None:
    addLeaves(node, value.items())
def addLeaves(node, items):
  items.sort()
  for key, value in items:
    addNode(node, key, value)
def makeTree(name, data):
  tree = Node("Sample Tree")
  addLeaves(tree, data.items())
  return swing.JTree(tree)
def exit(e): 
  java.lang.System.exit(0)
if __name__ == '__main__':
  tree = makeTree('Some JPython Classes', sampleData)
  button = swing.JButton('Close Me!', actionPerformed=exit)
  f = swing.JFrame("GridBag Layout Example");
  p = swing.JFrame.getContentPane(f)
  gb = awt.GridBagLayout()
  p.setLayout(gb)
  
  c = awt.GridBagConstraints();
  c.weightx = 1.0;
  c.fill = awt.GridBagConstraints.BOTH;
  
  gb.setConstraints(tree, c);
  c.gridx = 0;
  c.gridy = awt.GridBagConstraints.RELATIVE;
  gb.setConstraints(button, c);
  p.add(tree)
  p.add(button)
  f.pack();
Exemplo n.º 7
0
filler = JPanel()  #The empty table is placed here so I can later just order
table_data = []  #filler to validate itself and it will add the new table.
ColumnNames = ['Element', 'x Beta', 'y Beta']
table = JTable(table_data, ColumnNames)
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
for i in xrange(2):
    column = table.getColumnModel().getColumn(i)
    if i == 0:
        column.setPreferredWidth(150)  #The table is too wide if this is
    if i == 1:  #not included.
        column.setPreferredWidth(60)
    if i == 2:
        column.setPreferredWidth(60)
scroll = JScrollPane(table)
scroll.setPreferredSize(Dimension(280, 340))
filler.setPreferredSize(Dimension(280, 340))
filler.add(scroll)
#The table data was repeated so it displays the ColumnNames when the GUI
#first pops up.

#Frame stuff----------------------------------------------------------------
frame = swing.JFrame("Magnet Settings Interpolation")
frame.getContentPane().add(lpanel, BorderLayout.WEST)
frame.getContentPane().add(filler, BorderLayout.CENTER)
frame.getContentPane().add(plot, BorderLayout.SOUTH)
frame.pack()  #Makes the frame fit the components.
frame.setDefaultCloseOperation(swing.JFrame.EXIT_ON_CLOSE)
frame.show()
#If the default close operation is not set, it just hides the program when
#they try to close it.