本文整理汇总了Python中javax.swing.JFrame.pack方法的典型用法代码示例。如果您正苦于以下问题:Python JFrame.pack方法的具体用法?Python JFrame.pack怎么用?Python JFrame.pack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFrame
的用法示例。
在下文中一共展示了JFrame.pack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
def show():
""" adapted from here: http://wiki.gephi.org/index.php/Toolkit_-_Reuse_the_Preview_Applet"""
from javax.swing import JFrame
from java.awt import BorderLayout
pc = PreviewController
pc.refreshPreview();
# New Processing target, get the PApplet
target = pc.getRenderTarget("processing")
applet = target.getApplet()
applet.init()
# Refresh the preview and reset the zoom
try:
pc.render(target)
except Exception:
# throws sun.dc.pr.PRError: sun.dc.pr.PRError: setPenT4: invalid pen transformation (singular)
pass
target.refresh()
target.resetZoom()
# Add the applet to a JFrame and display
frame = JFrame("Preview")
frame.setLayout(BorderLayout())
# frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.add(applet, BorderLayout.CENTER)
frame.pack()
frame.setVisible(True)
示例2: tree
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
def tree():
"""
tree(xmlfile="dsm2.xml")
creates a tree view on a given xml file of dsm2 input data
"""
tv = TreeViewer()
mp2 = JPanel()
mp2.setLayout(BorderLayout())
tf = JTextField("dsm2.inp")
pb = JButton("parse")
mp2.add(tf,BorderLayout.CENTER)
mp2.add(pb,BorderLayout.EAST)
class ParseListener(ActionListener):
def __init__(self,tf,tv,fr):
self.tf = tf
self.tv = tv
self.fr = fr
def actionPerformed(self,evt):
dsm2file = self.tf.getText()
parser = DSM2Parser(dsm2file)
self.tv.xdoc = parser.dsm2_data.toXml()
self.fr.getContentPane().add(self.tv.gui(),BorderLayout.CENTER)
self.fr.pack()
self.fr.setVisible(1)
fr = JFrame()
fr.setTitle("DSM2Tree")
fr.setLocation(100,100)
fr.setSize(600,60)
fr.getContentPane().setLayout(BorderLayout())
fr.getContentPane().add(mp2,BorderLayout.NORTH)
al = ParseListener(tf,tv,fr)
pb.addActionListener(al)
fr.pack()
fr.setVisible(1)
示例3: gui_open
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
def gui_open(path):
label = JLabel(ImageIcon(ImageIO.read(File(URL(path).getFile()))))
frame = JFrame()
frame.getContentPane().add(label)
frame.pack()
frame.setLocation(200, 200)
frame.setVisible(True)
示例4: __init__
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
class _AccountAdder:
def __init__(self, contactslist):
self.contactslist = contactslist
self.mainframe = JFrame("Add New Contact")
self.account = JComboBox(self.contactslist.clientsByName.keys())
self.contactname = JTextField()
self.buildpane()
def buildpane(self):
buttons = JPanel()
buttons.add(JButton("OK", actionPerformed=self.add))
buttons.add(JButton("Cancel", actionPerformed=self.cancel))
acct = JPanel(GridLayout(1, 2), doublebuffered)
acct.add(JLabel("Account"))
acct.add(self.account)
mainpane = self.mainframe.getContentPane()
mainpane.setLayout(BoxLayout(mainpane, BoxLayout.Y_AXIS))
mainpane.add(self.contactname)
mainpane.add(acct)
mainpane.add(buttons)
self.mainframe.pack()
self.mainframe.show()
#action listeners
def add(self, ae):
acct = self.contactslist.clientsByName[self.account.getSelectedItem()]
acct.addContact(self.contactname.getText())
self.mainframe.dispose()
def cancel(self, ae):
self.mainframe.dispose()
示例5: VacalcFrame
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
class VacalcFrame(object):
def __init__(self, employees, dateprovider):
self._frame = JFrame("Vacation Calculator", defaultCloseOperation=JFrame.EXIT_ON_CLOSE)
self._frame.setContentPane(self._create_ui(employees, dateprovider))
self._frame.pack()
def _create_ui(self, employees, dateprovider):
panel = JPanel(layout=FlowLayout())
self._overview = EmployeeOverview(employees, self)
self._details = EmployeeDetails(employees, dateprovider)
self._welcome = Welcome()
panel.add(self._overview)
panel.add(self._welcome)
return panel
def show(self):
self._frame.setVisible(True)
def employee_selected(self, employee):
self._ensure_details_shown()
self._details.show_employee(employee)
def edit_new_employee(self):
self._ensure_details_shown()
self._details.edit_new_employee()
def _ensure_details_shown(self):
if self._welcome:
self._frame.contentPane.remove(self._welcome)
self._frame.contentPane.add(self._details)
self._frame.pack()
self._welcome = None
示例6: desty
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
class myAnimFrame:
"""
Supporting class for animations.
"""
def desty(self, event):
self.display.destroy()
self.frame.dispose()
def __init__(self, display, widget, width, height, title):
from javax.swing import JFrame, JPanel
from java.awt import BorderLayout, FlowLayout
self.display = display
self.panel = JPanel(BorderLayout())
self.panel2 = JPanel(FlowLayout())
self.panel2.add(widget)
self.panel.add("North", self.panel2)
self.panel.add("Center",self.display.getComponent())
self.frame = JFrame(title, windowClosing=self.desty)
self.pane = self.frame.getContentPane()
self.pane.add(self.panel)
self.frame.setSize(width,height)
self.frame.pack()
self.frame.show()
示例7: UI
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
class UI(object):
def __init__(self, game):
self.frame = JFrame("Tic Tac Toe",
defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE)
self.panel = JPanel(GridLayout(3,3))
self.buttons = []
self.game = game
for row in range(3):
for col in range(3):
self.buttons.append(TicTacButton(row,col,'',actionPerformed=self.clicked_button))
self.panel.add
self.frame.add(self.panel)
for b in self.buttons:
self.panel.add(b)
self.frame.pack()
self.show()
def show(self):
self.frame.size = 600,600
self.frame.visible = True
def clicked_button(self, event):
button = event.getSource()
print 'current_player', self.game.current_player
if self.game.current_player.level == 'human' and self.game.state=='next':
button.text = self.game.current_player.xo
self.game.update(button)
else:
pass
示例8: positionDialog
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
class positionDialog(JFrame):
def __init__(self):
self.frame = JFrame("CellCropper: Experiment details", size=(400,200))
self.frame.setLocation(20,120)
self.Panel = JPanel(GridLayout(4,2))
self.frame.add(self.Panel)
self.Panel.add(JLabel("Date:"))
self.dateField = JTextField( str(date.today()), 8 )
self.Panel.add(self.dateField)
self.strainField = JTextField( "2926",4 )
self.Panel.add(self.strainField)
self.tempField = JTextField( "34",2 )
self.Panel.add(self.tempField)
self.ODField = JTextField( "0.5",3 )
self.Panel.add(self.ODField)
self.condField = JTextField( "0.5",3 )
self.Panel.add(self.condField)
self.OKButton = JButton("OK",actionPerformed=closeAndMakePos)
self.Panel.add(self.OKButton)
self.frame.pack()
WindowManager.addWindow(self.frame)
self.show()
def show(self):
self.frame.visible = True
def close(self):
return self.dateField.text, self.strainField.text, self.tempField.text, self.ODField.text, self.condField.text
WindowManager.removeWindow(self.frame)
self.frame.dispose()
示例9: ConversationWindow
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
class ConversationWindow(Conversation):
"""A GUI window of a conversation with a specific person"""
def __init__(self, person, chatui):
"""ConversationWindow(basesupport.AbstractPerson:person)"""
Conversation.__init__(self, person, chatui)
self.mainframe = JFrame("Conversation with "+person.name)
self.display = JTextArea(columns=100,
rows=15,
editable=0,
lineWrap=1)
self.typepad = JTextField()
self.buildpane()
self.lentext = 0
def buildpane(self):
buttons = JPanel(doublebuffered)
buttons.add(JButton("Send", actionPerformed=self.send))
buttons.add(JButton("Hide", actionPerformed=self.hidewindow))
mainpane = self.mainframe.getContentPane()
mainpane.setLayout(BoxLayout(mainpane, BoxLayout.Y_AXIS))
mainpane.add(JScrollPane(self.display))
self.typepad.actionPerformed = self.send
mainpane.add(self.typepad)
mainpane.add(buttons)
def show(self):
self.mainframe.pack()
self.mainframe.show()
def hide(self):
self.mainframe.hide()
def sendText(self, text):
self.displayText("\n"+self.person.client.name+": "+text)
Conversation.sendText(self, text)
def showMessage(self, text, metadata=None):
self.displayText("\n"+self.person.name+": "+text)
def contactChangedNick(self, person, newnick):
Conversation.contactChangedNick(self, person, newnick)
self.mainframe.setTitle("Conversation with "+newnick)
#GUI code
def displayText(self, text):
self.lentext = self.lentext + len(text)
self.display.append(text)
self.display.setCaretPosition(self.lentext)
#actionlisteners
def hidewindow(self, ae):
self.hide()
def send(self, ae):
text = self.typepad.getText()
self.typepad.setText("")
if text != "" and text != None:
self.sendText(text)
示例10: startGui
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
def startGui():
frame = JFrame("MonkeyPySon")
frame.setContentPane(getContentPane())
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.pack()
frame.setVisible(True)
frame.addWindowFocusListener(GuiWindowFocusListener())
startLookingDevices()
示例11: cachedBPROM
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
def cachedBPROM(genome, fileName, frame):
"""
genome: Genome as a string.
fileName: File to save the BPROM results in.
swing: A JFrame or None. If this is None then messages will be printed, if it isn't then
they will also be put in a dialog box.
return: Results of the BPROM prediction stored in a list of Promoter objects.
If the file Specified by fileName already exists then this function simply parses the file
already there. Also, if a request is made to BPROM and nothing is returned, no file is
created, the user is warned, and an empty list is returned.
"""
offset = 25 if ".forward.bprom" in fileName else 50
direction = "forward" if offset == 50 else "reverse"
def getPromoters():
input = open(fileName, "r")
results = parseBPROM(input.read())
input.close()
return results
if not os.path.isfile(fileName):
results = urllib.urlopen("http://linux1.softberry.com/cgi-bin/programs/gfindb/bprom.pl",
urllib.urlencode({"DATA" : genome}))
resultString = results.read()
results.close()
resultString = resultString[resultString.find("<pre>"):resultString.find("</pre>")]
resultString = re.sub("<+.+>+", "", resultString).strip()
if resultString:
output = open(fileName, "w")
output.write(resultString)
output.close()
return getPromoters()
else:
if frame:
messageFrame = JFrame("BPROM Error",
defaultCloseOperation = WindowConstants.DISPOSE_ON_CLOSE)
messageFrame.setLocation(frame.location().x + offset, frame.location().y + offset)
messageFrame.contentPane.layout = GridBagLayout()
constraints = GridBagConstraints()
constraints.gridx, constraints.gridy = 0, 0
constraints.gridwidth, constraints.gridheight = 1, 1
constraints.fill = GridBagConstraints.BOTH
constraints.weightx, constraints.weighty = 1, 1
messageFrame.contentPane.add(JLabel("<html>The pipeline will continue to run but BPROM<br/>did not process the request for promoters on the<br/>" + direction + " strand. Try again tomorrow.</html>"), constraints)
constraints.gridx, constraints.gridy = 0, 1
constraints.fill = GridBagConstraints.NONE
constraints.weightx, constraints.weighty = 1, 1
constraints.anchor = GridBagConstraints.LINE_END
messageFrame.contentPane.add(JButton("Ok", actionPerformed = lambda e: messageFrame.dispose()), constraints)
messageFrame.pack()
messageFrame.visible = True
print "BPROM Error:", "The pipeline will continue to run but BPROM did not process the request for promoters on the " + direction + " strand. Try again tomorrow"
return []
else:
return getPromoters()
示例12: run
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
def run(sketch):
from javax.swing import JFrame
from processing.core import PApplet
class Main(PApplet):
def __init__(self, sketch):
self.sketch = sketch
P5_set_instance(self)
def setup(self):
self.sketch['setup']()
def draw(self):
self.sketch['draw']()
def mousePressed(self, evt):
P5_register_mouse_event(evt)
self.sketch['mousePressed']()
def mouseReleased(self, evt):
P5_register_mouse_event(evt)
def mouseClicked(self, evt):
P5_register_mouse_event(evt)
self.sketch['mouseClicked']()
def mouseEntered(self, evt):
P5_register_mouse_event(evt)
def mouseExited(self, evt):
P5_register_mouse_event(evt)
def mouseDragged(self, evt):
P5_register_mouse_event(evt)
self.sketch['mouseDragged'](evt)
def mouseMoved(self, evt):
P5_register_mouse_event(evt)
self.sketch['mouseMoved'](evt)
def getField(self, name):
# rqd due to PApplet's using frameRate and frameRate(n) etc.
return self.class.superclass.getDeclaredField(name).get(self)
if __name__ == '__main__' or True:
frame = JFrame(title="Processing",
resizable=0,
defaultCloseOperation=JFrame.EXIT_ON_CLOSE)
panel = Main(sketch)
frame.add(panel)
panel.init()
while panel.defaultSize and not panel.finished:
pass
frame.pack()
frame.visible = 1
示例13: View
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
class View(JComponent):
def __init__(self, obj, location, size=(800, 600), keys=None):
JComponent.__init__(self)
self.location = list(location)
self.buffer = FrameBuffer(
size[0], size[1], FrameBuffer.SAMPLINGMODE_NORMAL)
self.obj = obj
self.frame = JFrame(keyPressed=self.keyPressed,
keyReleased=self.keyReleased)
self.frame.add(self)
self.size = size
self.frame.pack()
self.frame.size = size
self.frame.visible = True
self.clearColor = Color(0x666666)
self.keys = keys
def paint(self, g):
x, y, z = self.location
self.obj.world.camera.setPosition(x, -y, z)
self.obj.world.camera.lookAt(SimpleVector(0, 0, 0))
self.buffer.clear(self.clearColor)
self.obj.world.renderScene(self.buffer)
self.obj.world.draw(self.buffer)
self.buffer.update()
self.buffer.display(g)
self.repaint()
def keyReleased(self, event):
if self.keys is not None and hasattr(self.keys, 'key_released'):
self.keys.key_released(KeyEvent.getKeyText(event.keyCode))
def keyPressed(self, event):
if self.keys is not None and hasattr(self.keys, 'key_pressed'):
self.keys.key_pressed(KeyEvent.getKeyText(event.keyCode))
if event.keyCode == KeyEvent.VK_ESCAPE:
self.frame.dispose()
elif event.keyCode == KeyEvent.VK_PAGE_UP:
self.obj.sch.rate *= 1.1
self.frame.title = 'rate: %1.3f' % self.obj.sch.rate
elif event.keyCode == KeyEvent.VK_PAGE_DOWN:
self.obj.sch.rate /= 1.1
self.frame.title = 'rate: %1.3f' % self.obj.sch.rate
elif event.keyCode == KeyEvent.VK_Z:
self.location[2] += 1
elif event.keyCode == KeyEvent.VK_X:
self.location[2] -= 1
elif event.keyCode == KeyEvent.VK_W:
self.location[1] += 1
elif event.keyCode == KeyEvent.VK_S:
self.location[1] -= 1
elif event.keyCode == KeyEvent.VK_A:
self.location[0] += 1
elif event.keyCode == KeyEvent.VK_D:
self.location[0] -= 1
示例14: run
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
def run(self, query, print_urls = True, pr_weight =0.4, verbose = False):
"""this function basically runs a query"""
self.query = parse_query(query, self.reader)
start_time = time.clock()
self.n_show = 10
if self.ah_flag is True:
doc_ids, score, auth_ids, auth_score, hub_ids, hub_score = self.retrieve(verbose = verbose)
elif self.pr_flag is True:
doc_ids, score, pr_ids, pr = self.retrieve(pr_weight = pr_weight, verbose = verbose)
else:
doc_ids, score = self.retrieve(verbose = verbose)
end_time = time.clock()
frame = JFrame('Ragav\'s Search Engine',
defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
size = (100, 200)
)
panel = JPanel(GridLayout(0,1))
frame.add(panel)
print "in total " + str(end_time - start_time) + " seconds for retrieval"
if print_urls is True:
# panel.add ( JLabel("vector space retreival" ) )
for i in xrange(self.n_show):
d = self.reader.document(doc_ids[i])
panel.add ( JLabel (d.getFieldable("path").stringValue().replace("%%", "/") ) )
print "doc: [" + str(doc_ids[i]) + "], score: [" + str(score[doc_ids[i]]) + "], url: " + d.getFieldable("path").stringValue().replace("%%", "/")
if self.ah_flag is True:
# panel.add ( Jlabel("authorities based retreival" ) )
for i in xrange(self.n_show):
d = self.reader.document(auth_ids[i])
panel.add ( JLabel (d.getFieldable("path").stringValue().replace("%%", "/") ) )
# panel.add ( JLabel("hubs based retreival" ) )
for i in xrange(self.n_show):
d = self.reader.document(hub_ids[i])
panel.add ( JLabel ( d.getFieldable("path").stringValue().replace("%%", "/") ) )
elif self.pr_flag is True:
# panel.add ( JLabel("page rank based retreival" ) )
for i in xrange(self.n_Show):
d = self.reader.document(pr_ids[i])
panel.add ( JLabel ( d.getFieldable("path").stringValue().replace("%%", "/") ) )
print "retrieval complete. "
print "..........................................................................."
frame.pack()
frame.visible = True
return d
示例15: ApplicationTestCase
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import pack [as 别名]
class ApplicationTestCase(unittest.TestCase):
def setUp(self):
Robot().mouseMove(800, 600)
self.launch_app()
self.app = ApplicationTestApp()
def tearDown(self):
self.frame.setVisible(False)
self.frame.dispose()
def launch_app(self):
self.frame = JFrame("Test Window", defaultCloseOperation=JFrame.EXIT_ON_CLOSE)
pane = self.frame.getContentPane()
layout = SpringLayout()
pane.setLayout(layout)
label = JLabel("Test Label")
pane.add(label)
layout.putConstraint(SpringLayout.WEST, label, 20, SpringLayout.WEST, pane)
layout.putConstraint(SpringLayout.NORTH, label, 20, SpringLayout.NORTH, pane)
self.frame.pack()
self.frame.setVisible(True)
self.frame.setSize(800, 600)
def test_init_window(self):
window = self.app.init_window(ApplicationTestWindow)
self.assertNotEqual(window, None)
self.assertTrue(isinstance(window, ApplicationTestWindow))
self.assertEqual((window.region.getW(), window.region.getH()), (800, 600))
def test_create_image_folders(self):
path = os.path.join('images', 'application_test_window', 'test_label')
shutil.move(os.path.join(path, 'enabled.png'), os.path.join('images', '.enabled.png.tmp'))
shutil.rmtree(os.path.join('images', 'application_test_window'))
self.app.create_image_folders()
self.assertTrue(os.path.exists(path))
shutil.move(os.path.join('images', '.enabled.png.tmp'), os.path.join(path, 'enabled.png'))
# TODO: test_capture_screenshots
# TODO: test_open
def test_find_focused_window(self):
window = self.app.find_focused_window()
self.assertNotEqual(window, None)
self.assertTrue(isinstance(window, ApplicationTestWindow))
def test_focused_window(self):
before_time = time.time()
window = self.app.focused_window(10)
after_time = time.time()
self.assertTrue(after_time >= before_time + 10)
self.assertNotEqual(window, None)
self.assertTrue(isinstance(window, ApplicationTestWindow))