源对象如何能够接收到对象在掉落时刻(DataSource)的反馈信息?
我有一个窗口 - EditWindow (类的对象,继承 wx.Frame ),其中包含 Grid 对象(self.grid)。 在这个类中,我编写了这个方法:
def OnSubindexGridCellLeftClick( self, event ):
....
dragSource = MyDropSource( self.grid )
dragSource.SetData( data )
dragSource.DoDragDrop()
event.Skip()
并将其绑定到 EditWindow 的 __init__
中:
self.grid.Bind( wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSubindexGridCellLeftClick )
在另一个窗口 - “VariableWindow” 中,我有另一个网格 - “VariablesGrid” 并且我确定以下类
class VariableDropTarget(wx.TextDropTarget):
def __init__(self, parent):
wx.TextDropTarget.__init__(self)
self.ParentWindow = parent
def OnDropText(self, x, y, data):
x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
....
:我设置的另一个窗口放置目标:
self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
当我从网格(位于 EditorWindow 中)放置光标时,如何挂钩对象的一些信息 - “VariablesGrid”。我想获取 VariablesGrid 中的数据信息,EditWindow 如何接收此信息? 抱歉我的英语不好。
I have one window - EditWindow ( object of class, which is inherit wx.Frame ), which contain Grid object (self.grid).
In this class i write this method:
def OnSubindexGridCellLeftClick( self, event ):
....
dragSource = MyDropSource( self.grid )
dragSource.SetData( data )
dragSource.DoDragDrop()
event.Skip()
and bind it in __init__
of EditWindow :
self.grid.Bind( wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSubindexGridCellLeftClick )
in the another window - "VariableWindow" i have got a another grid - "VariablesGrid" and i determine the following class:
class VariableDropTarget(wx.TextDropTarget):
def __init__(self, parent):
wx.TextDropTarget.__init__(self)
self.ParentWindow = parent
def OnDropText(self, x, y, data):
x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
....
In the another window i set drop target:
self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
How i can hook some information of object - "VariablesGrid" at the moment, when i drop cursor from grid (which is situated in EditorWindow). I want to take information of data in VariablesGrid and how EditWindow can receive this information ?
sorry for my bad English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 pubsub 将数据发送到 EditorWindow,然后显示它。仅在 OnDropText 方法中执行发送,以便仅当您在拖动结束时实际放置时才发送。这是一个关于 pubsub 的简单教程,可以帮助您入门: http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/
You could use pubsub to send the data to the EditorWindow and then display it. Do the sending in the OnDropText method only so it only sends when you actually drop at the end of the drag. Here's a simple tutorial on pubsub to get you going: http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/
让我们看看我是否理解这个问题。
您有一个“拖放”源窗口和一个“拖放”目标窗口。当用户执行拖放操作时,您希望将一些信息从目标窗口传递到源窗口。
这是正确的吗?
一般来说,这是无法做到的。正如名称所示,信息流是从源到目的地。
但是,如果源和目标位于同一正在运行的应用程序中,则可以通过让目标调用源中的方法来“伪造”它,在放置完成时将所需信息从目标传递到源。
如果这样做,您应该确保只有一个应用程序实例可以运行,否则如果用户在应用程序的两个副本之间拖放,将会导致混乱。
Let's see if I understand the question.
You have a 'drag and drop' source window and a 'drag and drop' destination window. You want to pass some information from the destination window to the source window when the user performs a drag and drop.
Is that correct?
In general, this cannot be done. The information flow is from the source to the destination, as suggested by the names.
However, if the source and destination are in the same running application, you can 'fake' it by having the destination call a method in the source, passing the required information from the destination to the source, when the drop is completed.
If you do this, you should ensure that only a single instance of the application can run, otherwise chaos will result if the user drags and drops between two copies of the application.