本文整理汇总了Python中javax.swing.JFrame.validate方法的典型用法代码示例。如果您正苦于以下问题:Python JFrame.validate方法的具体用法?Python JFrame.validate怎么用?Python JFrame.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFrame
的用法示例。
在下文中一共展示了JFrame.validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PythonWindow
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import validate [as 别名]
#.........这里部分代码省略.........
KeyEvent.VK_CLOSE_BRACKET)
editmenu.add(item)
item = new_item("Dedent Selection", "dedentselection",
KeyEvent.VK_OPEN_BRACKET)
editmenu.add(item)
shellmenu = JMenu("Interactive")
menubar.add(shellmenu)
item = new_item("Previous Input", "up", KeyEvent.VK_UP,
mod=ActionEvent.ALT_MASK)
shellmenu.add(item)
item = new_item("Next Input", "down", KeyEvent.VK_DOWN,
mod=ActionEvent.ALT_MASK)
shellmenu.add(item)
self.frame.setJMenuBar(menubar)
def toggle_visibility(self):
self.frame.visible = not self.frame.visible
def add_component(self, c):
self.remove_component()
self.frame.add(c, BorderLayout.PAGE_START)
self.component = c
def remove_component(self):
if self.component is not None:
self.frame.remove(self.component)
self.component = None
def add(self, text, type="input"):
self.outputpane.addtext(text, type)
self.frame.validate()
def error(self, text):
self.outputpane.addtext(text, "error", ensure_newline=True)
def write(self, text):
self.add(text, "output")
# Code execution methods
def runcode(self, source, interactive=True):
if not source.strip():
return True
processed_source = source.replace("$", "geo.")
code = self.interface.compileinteractive(processed_source)
if code in ("continue", "error"):
code = self.interface.compilemodule(processed_source)
if code == "error":
return
if code == "error":
return False
source = source.strip()
if interactive:
self.history.append(source)
self.current_text = ""
self.outputpane.addtext(source +'\n', "input", ensure_newline=True)
self.interface.run(code)
return True
def run(self):
source = self.input.text
if not source.strip():
self.input.text = ""
return
processed_source = source.replace("$", "geo.")
code = self.interface.compileinteractive(processed_source)
if code in ("continue", "error"):
示例2: PythonWindow
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import validate [as 别名]
class PythonWindow(KeyListener):
def __init__(self):
self.frame = JFrame("Python Window")
#self.historyList = JList(DefaultListModel())
#self.historyList.cellRenderer = MyListCellRenderer()
scrollpane = JScrollPane()
inputPanel = JPanel()
inputPanel.layout = GridLayout(1, 1)
self.input = JTextArea("")
self.input.border = BorderFactory.createEmptyBorder(5, 5, 5, 5)
self.input.tabSize = 4
self.input.font = Font("Monospaced", Font.PLAIN, 12)
self.input.addKeyListener(self)
inputPanel.add(self.input)
self.outputpane = OutputPane()
scrollpane.viewport.view = self.outputpane.textpane #self.historyList
self.frame.add(scrollpane, BorderLayout.CENTER)
self.frame.add(inputPanel, BorderLayout.PAGE_END)
self.frame.size = 500, 600
self.frame.visible = False
self.component = None
def toggle_visibility(self):
self.frame.visible = not self.frame.visible
def add_component(self, c):
self.remove_component()
self.frame.add(c, BorderLayout.PAGE_START)
self.component = c
def remove_component(self):
if self.component is not None:
self.frame.remove(self.component)
self.component = None
def add(self, text, type="input"):
self.outputpane.addtext(text, type)
#self.historyList.model.addElement({"text": text, "type": type})
#self.historyList.validate()
self.frame.validate()
#last = self.historyList.model.getSize() - 1
#self.historyList.ensureIndexIsVisible(last)
def error(self, text):
self.outputpane.addtext(text, "error", ensure_newline=True)
def write(self, text):
self.add(text, "output")
def run(self, evt):
source = self.input.text
if not source.strip():
self.input.text = ""
return
processed_source = source.replace("$", "geo.")
code = interface.compileinteractive(processed_source)
if code in ("continue", "error"):
code = interface.compilemodule(processed_source)
if code == "error":
return
source = source.strip() + '\n'
self.outputpane.addtext(source, "input", ensure_newline=True)
result = interface.run(code)
if result == "OK":
self.input.text = ""
def keyPressed(self, evt):
pass
def keyReleased(self, evt):
pass
def keyTyped(self, evt):
if evt.keyChar == '\n':
# Only try to run compound statements when they end with
# two \n
source = self.input.text
lines = source.split("\n")
if lines[0].rstrip().endswith(":") and not source.endswith("\n\n"):
for i, c in enumerate(lines[-2]):
if c not in ' \t': break
else:
self.run(evt)
return
prefix = lines[-2][:i]
if lines[-2].endswith(":"):
prefix += '\t'
self.input.text = source + prefix
else:
self.run(evt)