本文整理汇总了Python中javax.swing.SwingUtilities类的典型用法代码示例。如果您正苦于以下问题:Python SwingUtilities类的具体用法?Python SwingUtilities怎么用?Python SwingUtilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SwingUtilities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invokeThreadsafe
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: run_example
def run_example(network, runner):
"""Used to conveniently create a NengoGraphics instance
with an existing Network model.
"""
if isinstance(network, UINetwork):
model = network
model_ui = network
elif isinstance(network, NetworkImpl):
model = network
nengo = NengoGraphics()
task = TrackedStatusMsg("Creating Model UI")
model_ui = UINetwork(model)
nengo.world.ground.addChild(model_ui)
model_ui.openViewer()
task.finished()
print "Running example: " + network.name
# All UI functions and constructors must be invoked from the Swing
# Event Thread
if not isinstance(runner, Runnable):
runner = make_runnable(runner)
SwingUtilities.invokeLater(runner)
示例3: getButtonIdentifier
def getButtonIdentifier(self):
intFrame = SwingUtilities.getAncestorOfClass(JInternalFrame, self.widget.widget)
if intFrame:
return intFrame.getTitle()
icon = SwingUtilities.getAncestorOfClass(JInternalFrame.JDesktopIcon, self.widget.widget) # @UndefinedVariable
if icon:
return self.widget.widget.getLabel()
示例4: _swingRunner
def _swingRunner(func, *args, **kwargs):
if SwingUtilities.isEventDispatchThread():
return func(*args, **kwargs)
else:
wrappedCode = _JythonCallable(func, args, kwargs)
task = FutureTask(wrappedCode)
SwingUtilities.invokeLater(task)
return task.get()
示例5: runSwingLater
def runSwingLater(func, *args, **kwargs):
"""
Queues the given task to be run in the Event Dispatch Thread, regardless
of whether the calling thread is the EDT itself.
"""
runnable = RunnableWrapper(func, args, kwargs)
SwingUtilities.invokeLater(runnable)
示例6: action
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)
示例7: _swingWaitForResult
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()
示例8: runOnEventDispatchThread
def runOnEventDispatchThread(method, *args):
class EDTRunnable(Runnable):
def run(self):
method(*args)
if SwingUtilities.isEventDispatchThread():
method(*args)
else:
SwingUtilities.invokeAndWait(EDTRunnable())
示例9: hasComplexAncestors
def hasComplexAncestors(widget):
if any((SwingUtilities.getAncestorOfClass(widgetClass, widget) is not None
for widgetClass in [ JTable, JScrollBar, JComboBox, JSpinner ])):
return True
# If we're in a popup menu that's attached to something with complex ancestors, that's clearly even more complex :)
popup = SwingUtilities.getAncestorOfClass(JPopupMenu, widget)
if popup and isinstance(popup.getInvoker(), JComboBox):
return True
return popup is not None and hasComplexAncestors(popup.getInvoker())
示例10: runSwing
def runSwing(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 later.
:return: None
"""
if SwingUtilities.isEventDispatchThread():
func(*args, **kwargs)
else:
runnable = RunnableWrapper(func, args, kwargs)
SwingUtilities.invokeLater(runnable)
示例11: undoAction
def undoAction(self):
"""Undo the action."""
if not self.finished:
messages.showError("Action was never done, so it can't be undone")
return
"""Does the action layer, starts an appropriate thread"""
if self.spawn_thread and SwingUtilities.isEventDispatchThread():
threading.Thread(target=self.undoInternal).start()
elif self.spawn_thread or SwingUtilities.isEventDispatchThread():
# In the thread we want to be
self.undoInternal()
else:
SwingUtilities.invokeLater(RunWrapper(self.undoInternal))
示例12: buildNetwork
def buildNetwork(self, network):
network.name = "Integrator"
# Util.debugMsg("Network building started")
f = ConstantFunction(1, 1.0)
input = FunctionInput("input", [f], Units.UNK)
# uiViewer.addNeoNode(uiInput);
ef = NEFEnsembleFactoryImpl()
integrator = ef.make("integrator", 500, 1, "integrator1", False)
interm = integrator.addDecodedTermination("input", [[tau]], tau, False)
fbterm = integrator.addDecodedTermination("feedback", [[1.0]], tau, False)
network.addNode(integrator)
time.sleep(1)
network.addNode(input)
time.sleep(1)
# UINEFEnsemble uiIntegrator = new UINEFEnsemble(integrator);
# uiViewer.addNeoNode(uiIntegrator);
# uiIntegrator.collectSpikes(true);
# UITermination uiInterm =
# uiIntegrator.showTermination(interm.getName());
# UITermination uiFbterm =
# uiIntegrator.showTermination(fbterm.getName());
network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), interm)
time.sleep(0.5)
network.addProjection(integrator.getOrigin(NEFEnsemble.X), fbterm)
time.sleep(0.5)
# Test removing projections
network.removeProjection(interm)
time.sleep(0.5)
# add the projection back
network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), interm)
time.sleep(0.5)
# Add probes
integratorXProbe = network.simulator.addProbe("integrator", NEFEnsemble.X, True)
time.sleep(0.5)
# Test adding removing probes
network.simulator.removeProbe(integratorXProbe)
time.sleep(0.5)
# add the probe back
network.simulator.addProbe("integrator", NEFEnsemble.X, True)
time.sleep(0.5)
SwingUtilities.invokeLater(make_runnable(self.doPostUIStuff))
示例13: snapshot
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
示例14: selectWindow
def selectWindow(widget):
w = checkWidget(widget)
window = SwingUtilities.getWindowAncestor(w)
if isinstance(window, JFrame):
runKeyword("selectWindow", window.getTitle())
elif isinstance(window, JDialog):
runKeyword("selectDialog", window.getTitle())
示例15: _swingWaitForResult
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()