seqRoot = Node(seq.getId()) treeRoot.add(seqRoot) for ix in range(lattice.len()): el = lattice.getItem(ix) pos = el.getPosition() length = el.getLength() strt_pos = el.getAbsPosition() - length * 0.5 label = "s=" + repr(strt_pos) + " m," label += " l=" + repr(length) + " m," label += " p=" + repr(pos) + " m" leave = Node(label) branch = Node(el.getName()) branch.add(leave) seqRoot.add(branch) return treeRoot #................................................................... if __name__ == '__main__': #print "processing: jython",sys.argv[0] acc = getAccelerator() tree1 = makeXALTree('XAL Sequences & Nodes', acc) tree2 = makeLatticeTree('Lattice Trees', acc) pane1 = swing.JScrollPane(swing.JTree(tree1)) pane2 = swing.JScrollPane(swing.JTree(tree2)) main = swing.Box.createHorizontalBox() main.add(pane1) main.add(pane2) swing.test(main, (900, 500), sys.argv[0])
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) panel = swing.JPanel(awt.BorderLayout()) # make a swing panel panel.add("North", display) # text plus key grid in middle panel.add("Center", keys) swing.test(panel) # start in a GUI viewer
from pawt import swing lst = swing.JList(['a', 'b', 'c']) swing.test(lst)
except: exc_type, exc_value, exc_traceback = sys.exc_info() l = len(traceback.extract_tb(sys.exc_traceback)) try: 1/0 except: m = len(traceback.extract_tb(sys.exc_traceback)) traceback.print_exception(exc_type, exc_value, exc_traceback, l-m) self.console.newInput() def stopPython(self): # Should spend 2 seconds trying to kill thread in nice Python style first... self.stop() header = """\ JPython %(version)s on %(platform)s %(copyright)s """ % {'version': sys.version, 'platform': sys.platform, 'copyright': sys.copyright} if __name__ == '__main__': c = Console() pane = swing.JScrollPane(c.textpane) swing.test(pane, size=(500, 400), name='JPython Console') c.write(header, 'output') c.capturePythonOutput() c.textpane.requestFocus() c.newInput()
1 / 0 except: m = len(traceback.extract_tb(sys.exc_traceback)) traceback.print_exception(exc_type, exc_value, exc_traceback, l - m) self.console.newInput() def stopPython(self): #Should spend 2 seconds trying to kill thread in nice Python style first... self.stop() header = """\ JPython %(version)s on %(platform)s %(copyright)s """ % { 'version': sys.version, 'platform': sys.platform, 'copyright': sys.copyright } if __name__ == '__main__': c = Console() pane = swing.JScrollPane(c.textpane) swing.test(pane, size=(500, 400), name='JPython Console') c.write(header, 'output') c.capturePythonOutput() c.textpane.requestFocus() c.newInput()
for child in self.getChildren(): if child == node: return index index = index+1 return -1 def getParent(self): return self.myparent def toString(self): return self.name+' = '+shortrepr(self.object) if __name__ == '__main__': class foo: bar = 99 eggs = 'hello' class baz: x, y, z = 1, 2, 3 func = range import __main__ f = foo() f.pyfunc = mydir root = ObjectNode(None, 'foo', __main__) tree = swing.JTree(root) swing.test(swing.JScrollPane(tree))
'.', '=', '/' ] 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) panel = swing.JPanel(awt.BorderLayout()) # make a swing panel panel.add("North", display) # text plus key grid in middle panel.add("Center", keys) swing.test(panel)
__author__ = 'han' import java from java import awt java.lang.System.out.println('Heelooo') def exit(e): java.lang.System.exit(0) frame = awt.Frame('AWT Example', visible=1) button = awt.Button('Close Me!', actionPerformed=exit) frame.add(button, 'Center') frame.pack() from pawt import swing swing.test()
#the lattice tree seqRoot=Node(seq.getId()) treeRoot.add(seqRoot) for ix in range(lattice.len()): el=lattice.getItem(ix) pos=el.getPosition() length=el.getLength() strt_pos=el.getAbsPosition()-length*0.5 label="s="+repr(strt_pos)+" m," label+=" l="+repr(length)+" m," label+=" p="+repr(pos)+" m" leave=Node(label) branch=Node(el.getName()) branch.add(leave) seqRoot.add(branch) return treeRoot #................................................................... if __name__ == '__main__': #print "processing: jython",sys.argv[0] acc=getAccelerator() tree1=makeXALTree('XAL Sequences & Nodes', acc) tree2=makeLatticeTree('Lattice Trees',acc) pane1=swing.JScrollPane(swing.JTree(tree1)) pane2=swing.JScrollPane(swing.JTree(tree2)) main=swing.Box.createHorizontalBox() main.add(pane1) main.add(pane2) swing.test(main,(900,500),sys.argv[0])
for child in self.getChildren(): if child == node: return index index = index+1 return -1 def getParent(self): return self.myparent def toString(self): return self.name+' = '+shortrepr(self.object) if __name__ == '__main__': class foo: bar=99 eggs='hello' class baz: x,y,z=1,2,3 func = range import __main__ f = foo() f.pyfunc = mydir root = ObjectNode(None, 'foo', __main__) tree = swing.JTree(root) swing.test(swing.JScrollPane(tree))
'__builtin__':None, 'ThreadState':None, } from pawt import swing Node = swing.tree.DefaultMutableTreeNode def addNode(tree, key, value): node = Node(key) tree.add(node) 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('A Few JPython Classes') addLeaves(tree, data.items()) return tree if __name__ == '__main__': tree = makeTree('Some JPython Classes', data) panel=swing.JTree(tree) jp=swing.JScrollPane() jp.add(panel) swing.test(swing.JScrollPane(jp))