本文整理汇总了Python中javax.swing.SwingUtilities.invokeAndWait方法的典型用法代码示例。如果您正苦于以下问题:Python SwingUtilities.invokeAndWait方法的具体用法?Python SwingUtilities.invokeAndWait怎么用?Python SwingUtilities.invokeAndWait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.SwingUtilities
的用法示例。
在下文中一共展示了SwingUtilities.invokeAndWait方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invokeThreadsafe
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def invokeThreadsafe(fn, *args, **kwargs):
if SwingUtilities.isEventDispatchThread():
return fn(*args, **kwargs)
else:
task = FunctionCall(fn, args, kwargs)
SwingUtilities.invokeAndWait(task)
return task.getResult()
示例2: _swingWaitForResult
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def _swingWaitForResult(func, *args, **kwargs):
if SwingUtilities.isEventDispatchThread():
return func(*args, **kwargs)
wrappedCode = _JythonCallable(func, args, kwargs)
task = FutureTask(wrappedCode)
SwingUtilities.invokeAndWait(task)
return task.get()
示例3: action
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def action(self):
node = ModelFactory.constructModel(constructable)
if node is None:
raise Exception("No model was created")
elif isinstance(node, Node):
SwingUtilities.invokeAndWait(make_runnable(self.add_and_open))
else:
raise Exception("Can not add model of the type: " + node.class.simpleName)
示例4: runOnEventDispatchThread
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def runOnEventDispatchThread(method, *args):
class EDTRunnable(Runnable):
def run(self):
method(*args)
if SwingUtilities.isEventDispatchThread():
method(*args)
else:
SwingUtilities.invokeAndWait(EDTRunnable())
示例5: snapshot
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def snapshot(frame, box):
bi = BufferedImage(box.width, box.height, BufferedImage.TYPE_INT_RGB)
g = bi.createGraphics()
g.translate(-box.x, -box.y)
# all black! # frame.paintAll(g)
# only swing components! # frame.paint(g)
# only swing components! # frame.update(g)
# together, also only swing and with errors
##frame.update(g)
##frame.paint(g)
# locks the entire graphics machinery # frame.printAll(g)
# Finally, the right one:
SwingUtilities.invokeAndWait(PrintAll(frame, g))
return bi
示例6: _swingWaitForResult
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def _swingWaitForResult(func, *args, **kwargs):
# the naming of this function, along with _swingRunner, is kinda
# misleading; both functions will "wait" for the result (due to the get()).
# the difference between the two is that this function "wraps"
# invokeAndWait, while _swingRunner "wraps" invokeLater.
#
# the real world difference is that this function puts its Task at the
# beginning of the event dispatch thread, while _swingRunner appends to the
# end of the queue.
if SwingUtilities.isEventDispatchThread():
return func(*args, **kwargs)
wrappedCode = _JythonCallable(func, args, kwargs)
task = FutureTask(wrappedCode)
SwingUtilities.invokeAndWait(task)
return task.get()
示例7: callSwing
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def callSwing(func, *args, **kwargs):
"""
Runs the given function in the Event Dispatch Thread.
If this is invoked inside the EDT, the given function will be run normally.
Otherwise, it'll be queued to be run and the calling thread will block
until the function has been executed.
:return: func's return value
"""
if SwingUtilities.isEventDispatchThread():
return func(*args, **kwargs)
callable = CallableWrapper(func, args, kwargs)
task = FutureTask(callable)
SwingUtilities.invokeAndWait(task)
return task.get()
示例8: readInput
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def readInput(self, message):
#to be threadsafe on this call we need this to update the command window
class outputPromptRunner(Runnable):
def __init__(self, cw, m):
self.commandWindow = cw
self.message = m
def run(self):
#display the message and reenable the window to editing
self.commandWindow.showText(self.message)
self.commandWindow.setCaretPosition(self.commandWindow.document.getLength() )
self.commandWindow.setKeymap(self.commandWindow.my_keymap)
#--------------The Actual work goes here------------------
if not message:
message = ""
#first assign value to null
self.value = None
#note that the this interpreter thread needs to wait now
#until a result comes back from the command window
self.waitingFlag = True
#update the command window with the ouput
SwingUtilities.invokeAndWait(outputPromptRunner(self.commandWindow, message))
#Now we wait for the user to input a value and press ENTER in the command window,
#pausing a 10th of a second between checks.
while self.waitingFlag:
time.sleep(0.1)
#clean up the return value to remove the prompt since the command
#window will give us everything
self.value = self.value[len(message):]
#return the value to media.py
return self.value
示例9: invokeAndWait
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def invokeAndWait(func, *args, **kwargs):
"""Convenience method for SwingUtilities.invokeAndWait()."""
SwingUtilities.invokeAndWait(ProcRunnable(func, *args, **kwargs))
return
示例10: resizeImage
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
imageReader.setInput(inputStream)
return imageReader.read(0)
def resizeImage(self, fullSizeImage):
bufferedImage = BufferedImage(SwingingMonkeyCommander._preferredWidth, SwingingMonkeyCommander._preferredHeight, BufferedImage.TRANSLUCENT)
graphics2d = bufferedImage.createGraphics()
graphics2d.addRenderingHints(RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY))
graphics2d.drawImage(fullSizeImage, 0, 0, SwingingMonkeyCommander._preferredWidth, SwingingMonkeyCommander._preferredHeight, None)
graphics2d.dispose()
SwingingMonkeyCommander._widthScale = float(fullSizeImage.getWidth()) / float(bufferedImage.getWidth())
SwingingMonkeyCommander._heightScale = float(fullSizeImage.getHeight()) / float(bufferedImage.getHeight())
return bufferedImage
def done(self):
try:
self.get() #raise exception if abnormal completion
except ExecutionException, e:
raise SystemExit, e.getCause()
class Runnable(Runnable):
def __init__(self, runFunction):
self._runFunction = runFunction
def run(self):
self._runFunction()
if __name__ == '__main__':
SwingUtilities.invokeAndWait(Runnable(SwingingMonkeyCommander))
while True:
time.sleep(1000)
示例11: run
# 需要导入模块: from javax.swing import SwingUtilities [as 别名]
# 或者: from javax.swing.SwingUtilities import invokeAndWait [as 别名]
def run(self):
SwingUtilities.invokeAndWait(make_runnable(self.createUINetwork(NengoGraphics())))