当前位置: 首页>>代码示例>>Python>>正文


Python JMenuItem.setEnabled方法代码示例

本文整理汇总了Python中javax.swing.JMenuItem.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python JMenuItem.setEnabled方法的具体用法?Python JMenuItem.setEnabled怎么用?Python JMenuItem.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JMenuItem的用法示例。


在下文中一共展示了JMenuItem.setEnabled方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init

# 需要导入模块: from javax.swing import JMenuItem [as 别名]
# 或者: from javax.swing.JMenuItem import setEnabled [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)
开发者ID:Steell,项目名称:Ray-Tracer-Jython,代码行数:61,代码来源:RTApplet.py

示例2: run

# 需要导入模块: from javax.swing import JMenuItem [as 别名]
# 或者: from javax.swing.JMenuItem import setEnabled [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()
开发者ID:Steell,项目名称:Ray-Tracer-Jython,代码行数:77,代码来源:RTApplet.py

示例3: HRRGraph

# 需要导入模块: from javax.swing import JMenuItem [as 别名]
# 或者: from javax.swing.JMenuItem import setEnabled [as 别名]
class HRRGraph(graph.Graph):
    def __init__(self, view, name, func, args=(), filter=True, ylimits=(-1.0, 1.0), label=None, nodeid=None):
        self.fixed_value = None
        self.cache = {}
        self.cache_dt_tau = None
        self.cache_tick_count = 0

        graph.Graph.__init__(self, view, name, func, args=args, filter=filter, ylimits=ylimits, split=False, neuronmapped=False, label=label)

        self.border_top = 30

        self.vocab = hrr.Vocabulary.registered.get(nodeid, None)
        if self.vocab is None:
            dim = len(self.data.get_first())
            if dim in hrr.Vocabulary.defaults.keys():
                self.vocab = hrr.Vocabulary.defaults[dim]
            else:
                self.vocab = hrr.Vocabulary(dim)

        self.hidden_pairs = None
        self.normalize = True
        self.popup_normalize = JCheckBoxMenuItem('normalize', self.normalize, stateChanged=self.toggle_normalize)
        self.popup.add(self.popup_normalize)
        self.smooth_normalize = False
        self.popup_smooth = JCheckBoxMenuItem('smooth normalize', self.smooth_normalize, stateChanged=self.toggle_smooth_normalize)
        self.smooth_normalize_threshold = 0.4
        self.popup.add(self.popup_smooth)

        self.show_pairs = False
        self.popup_pairs = JCheckBoxMenuItem('show pairs', self.show_pairs, stateChanged=self.toggle_show_pairs)
        self.popup.add(self.popup_pairs)

        self.show_graph = True
        self.popup_graph = JCheckBoxMenuItem('show graph', self.show_graph, stateChanged=self.toggle_show_graph)
        self.popup.add(self.popup_graph)
        self.font_height_50 = None

        self.popup_set = JMenuItem('set value', actionPerformed=self.set_value)
        self.popup.add(self.popup_set)
        self.popup_release = JMenuItem('release value', actionPerformed=self.release_value)
        self.popup_release.setEnabled(False)
        self.popup.add(self.popup_release)

    def toggle_normalize(self, event):
        if event.source.state == self.normalize:
            return
        self.normalize = event.source.state
        if self.normalize and self.smooth_normalize:
            self.popup_smooth.state = False
        self.clear_cache()
        self.repaint()

    def toggle_smooth_normalize(self, event):
        if event.source.state == self.smooth_normalize:
            return
        self.smooth_normalize = event.source.state
        if self.smooth_normalize and self.normalize:
            self.popup_normalize.state = False
        self.clear_cache()
        self.repaint()

    def toggle_show_pairs(self, event):
        if event.source.state == self.show_pairs:
            return
        self.show_pairs = event.source.state

        self.redo_indices()

    def toggle_show_graph(self, event):
        self.show_graph = event.source.state

    def redo_indices(self):
        if self.indices is None:
            return
        self.clear_cache()

        if self.show_pairs:
            if self.vocab.vector_pairs is None:
                self.vocab.generate_pairs()

        pairs = self.indices[len(self.vocab.keys):]
        if self.hidden_pairs is not None:
            pairs.extend(self.hidden_pairs)
        pairs = pairs + [False] * (len(self.vocab.key_pairs) - len(pairs))
        self.indices = self.indices[:len(self.vocab.keys)]
        if len(self.indices) < len(self.vocab.keys):
            self.indices.extend([True] * (len(self.vocab.keys) - len(self.indices)))

        if self.show_pairs:
            self.indices = self.indices + pairs
            self.hidden_pairs = None
        else:
            self.hidden_pairs = pairs
        self.refix_popup()
        self.repaint()

    def save(self):
        info = graph.Graph.save(self)
        info['show_pairs'] = self.show_pairs
        info['normalize'] = self.normalize
#.........这里部分代码省略.........
开发者ID:Elhamahm,项目名称:nengo_1.4,代码行数:103,代码来源:hrrgraph.py


注:本文中的javax.swing.JMenuItem.setEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。