本文整理汇总了Python中javax.swing.JMenuItem.setAccelerator方法的典型用法代码示例。如果您正苦于以下问题:Python JMenuItem.setAccelerator方法的具体用法?Python JMenuItem.setAccelerator怎么用?Python JMenuItem.setAccelerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.setAccelerator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from javax.swing import JMenuItem [as 别名]
# 或者: from javax.swing.JMenuItem import setAccelerator [as 别名]
def init(self):
w, h, aa, threads = (512, 512, 1, 2)
canvas = RayTracePanel(w, h, aa, threads)
self.getContentPane().add(JScrollPane(canvas))
# Save FileChooser
# fcS = JFileChooser()
# fcS.addChoosableFileFilter(FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp']))
# fcS.addChoosableFileFilter(FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg']))
# fcS.addChoosableFileFilter(FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png']))
# def saveFile(event):
# '''Performed when the save button is pressed'''
# result = fcS.showSaveDialog(frame)
# if result == JFileChooser.APPROVE_OPTION:
# file = fcS.getSelectedFile()
# fname = file.getPath()
# ext = fcS.getFileFilter().getExtensions()[0]
# if not fname.endswith('.' + ext):
# file = File(fname + '.' + ext)
# canvas.saveToFile(file, ext)
# Open FileChooser
# fcO = JFileChooser()
# fcO.addChoosableFileFilter(FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts']))
# def openFile(event):
# '''Performed when the open button is pressed'''
# result = fcO.showOpenDialog(frame)
# if result == JFileChooser.APPROVE_OPTION:
# fname = fcO.getSelectedFile().getPath()
# if fname.endswith('.rts'):
# f = open(fname, 'rb')
# newScene = SceneFactory().buildScene(f)
# f.close()
# Painter(canvas, newScene, openButton, saveButton, stopButton).start()
def stop(event):
"""Peformed when the stop button is pressed"""
canvas.stopRendering()
# Setup Menu
menuBar = JMenuBar()
menu = JMenu("File")
menuBar.add(menu)
openButton = JMenuItem("Open...", actionPerformed=openFile)
openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
menu.add(openButton)
# saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
# saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
# menu.add(saveButton)
menu.addSeparator()
stopButton = JMenuItem("Stop Render", actionPerformed=stop)
stopButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0))
stopButton.setEnabled(False)
menu.add(stopButton)
menu.addSeparator()
# closeButton = JMenuItem('Close', actionPerformed=exit)
# closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
# menu.add(closeButton)
self.setJMenuBar(menuBar)
示例2: createAction
# 需要导入模块: from javax.swing import JMenuItem [as 别名]
# 或者: from javax.swing.JMenuItem import setAccelerator [as 别名]
def createAction(callback, name, description=None, menu=None, mnemonic=None, accelerator=None, toolBar=None, menuItemType="standard"):
action = CallbackAction(callback, name, description)
if menu:
if menuItemType == "standard":
menuItem = JMenuItem(action)
elif menuItemType == "checkbox":
menuItem = JCheckBoxMenuItem(action)
elif menuItemType == "radiobutton":
menuItem = JRadioButtonMenuItem(action)
else:
internal_error("unsupported menu item type %s" % `menuItemType`)
menuItem = JMenuItem(action)
if mnemonic:
menuItem.setMnemonic(mnemonic)
if accelerator:
menuItem.setAccelerator(KeyStroke.getKeyStroke(ord(accelerator), Event.CTRL_MASK, 0))
menu.add(menuItem)
action.setMenuItem(menuItem)
if toolBar:
toolbarButton = JButton(action)
toolBar.add(toolbarButton)
return action
示例3: run
# 需要导入模块: from javax.swing import JMenuItem [as 别名]
# 或者: from javax.swing.JMenuItem import setAccelerator [as 别名]
def run(scene, w=512, h=512, aa=1, threads=1):
"""Create GUI and perform ray-tracing."""
# Make Swing not look like garbage (so much)
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
# Setup frame
frame = JFrame("RayTracer", defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(w, h))
frame.setIconImage(ImageIcon("resources/icon.png").getImage())
canvas = RayTracePanel(w, h, aa, threads)
frame.getContentPane().add(JScrollPane(canvas))
# Save FileChooser
fcS = JFileChooser()
fcS.addChoosableFileFilter(FileNameExtensionFilter("Windows Bitmap (*.bmp)", ["bmp"]))
fcS.addChoosableFileFilter(FileNameExtensionFilter("JPEG / JFIF (*.jpg)", ["jpg"]))
fcS.addChoosableFileFilter(FileNameExtensionFilter("Portable Network Graphics (*.png)", ["png"]))
def saveFile(event):
"""Performed when the save button is pressed"""
result = fcS.showSaveDialog(frame)
if result == JFileChooser.APPROVE_OPTION:
file = fcS.getSelectedFile()
fname = file.getPath()
ext = fcS.getFileFilter().getExtensions()[0]
if not fname.endswith("." + ext):
file = File(fname + "." + ext)
canvas.saveToFile(file, ext)
# Open FileChooser
fcO = JFileChooser()
fcO.addChoosableFileFilter(FileNameExtensionFilter("RayTrace Scene File (*.rts)", ["rts"]))
def openFile(event):
"""Performed when the open button is pressed"""
result = fcO.showOpenDialog(frame)
if result == JFileChooser.APPROVE_OPTION:
fname = fcO.getSelectedFile().getPath()
if fname.endswith(".rts"):
f = open(fname, "rb")
newScene = SceneFactory().buildScene(f)
f.close()
Painter(canvas, newScene, openButton, saveButton, stopButton).start()
def exit(event):
"""Performed when the exit button is pressed"""
import sys
sys.exit(0)
def stop(event):
"""Peformed when the stop button is pressed"""
canvas.stopRendering()
# Setup Menu
menuBar = JMenuBar()
menu = JMenu("File")
menuBar.add(menu)
openButton = JMenuItem("Open...", actionPerformed=openFile)
openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
menu.add(openButton)
saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
menu.add(saveButton)
menu.addSeparator()
stopButton = JMenuItem("Stop Render", actionPerformed=stop)
stopButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0))
stopButton.setEnabled(False)
menu.add(stopButton)
menu.addSeparator()
closeButton = JMenuItem("Close", actionPerformed=exit)
closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
menu.add(closeButton)
frame.setJMenuBar(menuBar)
# Finish initializing GUI
self.pack()
示例4: menu_with_accelerator
# 需要导入模块: from javax.swing import JMenuItem [as 别名]
# 或者: from javax.swing.JMenuItem import setAccelerator [as 别名]
def menu_with_accelerator(menuText, accelerator_pair):
menu = JMenuItem(menuText)
menu.setAccelerator(KeyStroke.getKeyStroke(*accelerator_pair))
return menu
示例5: run
# 需要导入模块: from javax.swing import JMenuItem [as 别名]
# 或者: from javax.swing.JMenuItem import setAccelerator [as 别名]
def run(scene, w=512, h=512, aa=1, threads=1):
'''Create GUI and perform ray-tracing.'''
#Make Swing not look like garbage (so much)
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
#Setup frame
frame = JFrame(
"RayTracer",
defaultCloseOperation=JFrame.EXIT_ON_CLOSE,
size=(w, h)
)
frame.setIconImage(ImageIcon('resources/icon.png').getImage())
canvas = RayTracePanel(w, h, aa, threads)
frame.getContentPane().add(JScrollPane(canvas))
#Save FileChooser
fcS = JFileChooser()
fcS.addChoosableFileFilter(FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp']))
fcS.addChoosableFileFilter(FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg']))
fcS.addChoosableFileFilter(FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png']))
def saveFile(event):
'''Performed when the save button is pressed'''
result = fcS.showSaveDialog(frame)
if result == JFileChooser.APPROVE_OPTION:
file = fcS.getSelectedFile()
fname = file.getPath()
ext = fcS.getFileFilter().getExtensions()[0]
if not fname.endswith('.' + ext):
file = File(fname + '.' + ext)
canvas.saveToFile(file, ext)
#Open FileChooser
fcO = JFileChooser()
fcO.addChoosableFileFilter(FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts']))
def openFile(event):
'''Performed when the open button is pressed'''
result = fcO.showOpenDialog(frame)
if result == JFileChooser.APPROVE_OPTION:
fname = fcO.getSelectedFile().getPath()
if fname.endswith('.rts'):
f = open(fname, 'rb')
newScene = SceneFactory().buildScene(f)
f.close()
Painter(canvas, newScene, openButton, saveButton).start()
def exit(event):
'''Performed when the exit button is pressed'''
import sys
sys.exit(0)
#Setup Menu
menuBar = JMenuBar()
menu = JMenu("File")
menuBar.add(menu)
openButton = JMenuItem("Open...", actionPerformed=openFile)
openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
menu.add(openButton)
saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
menu.add(saveButton)
menu.addSeparator()
closeButton = JMenuItem('Close', actionPerformed=exit)
closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
menu.add(closeButton)
frame.setJMenuBar(menuBar)
#Finish initializing GUI
frame.pack()
#frame.setLocationRelativeTo(None)
frame.setVisible(True)
#Perform ray-tracing
if scene is not None:
Thread(Painter(canvas, scene, openButton, saveButton)).start()