源对象如何能够接收到对象在掉落时刻(DataSource)的反馈信息?

发布于 2024-12-08 14:47:16 字数 1084 浏览 0 评论 0原文

我有一个窗口 - 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼窥荷 2024-12-15 14:47:16

您可以使用 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/

傲鸠 2024-12-15 14:47:16

让我们看看我是否理解这个问题。

您有一个“拖放”源窗口和一个“拖放”目标窗口。当用户执行拖放操作时,您希望将一些信息从目标窗口传递到源窗口。

这是正确的吗?

一般来说,这是无法做到的。正如名称所示,信息流是从源到目的地。

但是,如果源和目标位于同一正在运行的应用程序中,则可以通过让目标调用源中的方法来“伪造”它,在放置完成时将所需信息从目标传递到源。

如果这样做,您应该确保只有一个应用程序实例可以运行,否则如果用户在应用程序的两个副本之间拖放,将会导致混乱。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文