如何检查项目是否已删除?wxpython?

如何检查项目是否已删除?wxpython?,python,wxpython,Python,Wxpython,使用wxpython的DragAndDrop,是否有一种方法可以获取文本何时被删除,然后执行一个函数?(我在找一种类似于捆绑的东西)。网上似乎没有任何关于如何做到这一点的例子 上面写着 通过调用SetDataObject将wxDataObject绑定到drop目标。你 还希望在drop中保留指向wxDataObject的指针 目标实例,以便您可以在 OnData方法 然而,我不知道这意味着什么 __author__ = 'David Woods, Wisconsin Center for Edu

使用wxpython的DragAndDrop,是否有一种方法可以获取文本何时被删除,然后执行一个函数?(我在找一种类似于捆绑的东西)。网上似乎没有任何关于如何做到这一点的例子

上面写着

通过调用SetDataObject将wxDataObject绑定到drop目标。你 还希望在drop中保留指向wxDataObject的指针 目标实例,以便您可以在 OnData方法

然而,我不知道这意味着什么

__author__ = 'David Woods, Wisconsin Center for Education Research <dwoods@wcer.wisc.edu>'

# Import wx.Python
import wx
# Declare GUI Constants
MENU_FILE_EXIT = wx.NewId()
DRAG_SOURCE    = wx.NewId()

# Define Text Drop Target class
class TextDropTarget(wx.TextDropTarget):
   """ This object implements Drop Target functionality for Text """
   def __init__(self, obj):
      """ Initialize the Drop Target, passing in the Object Reference to
          indicate what should receive the dropped text """
      # Initialize the wx.TextDropTarget Object
      wx.TextDropTarget.__init__(self)
      # Store the Object Reference for dropped text
      self.obj = obj

   def OnDropText(self, x, y, data):
      """ Implement Text Drop """
      # When text is dropped, write it into the object specified
      self.obj.WriteText(data + '\n\n')

# Define File Drop Target class
class FileDropTarget(wx.FileDropTarget):
   """ This object implements Drop Target functionality for Files """
   def __init__(self, obj):
      """ Initialize the Drop Target, passing in the Object Reference to
          indicate what should receive the dropped files """
      # Initialize the wxFileDropTarget Object
      wx.FileDropTarget.__init__(self)
      # Store the Object Reference for dropped files
      self.obj = obj

   def OnDropFiles(self, x, y, filenames):
      """ Implement File Drop """
      # For Demo purposes, this function appends a list of the files dropped at the end of the widget's text
      # Move Insertion Point to the end of the widget's text
      self.obj.SetInsertionPointEnd()
      # append a list of the file names dropped
      self.obj.WriteText("%d file(s) dropped at %d, %d:\n" % (len(filenames), x, y))
      for file in filenames:
         self.obj.WriteText(file + '\n')
      self.obj.WriteText('\n')

class MainWindow(wx.Frame):
   """ This window displays the GUI Widgets. """
   def __init__(self,parent,id,title):
       wx.Frame.__init__(self,parent,-4, title, size = (800,600), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
       self.SetBackgroundColour(wx.WHITE)

       # Menu Bar
       # Create a MenuBar
       menuBar = wx.MenuBar()
       # Build a Menu Object to go into the Menu Bar
       menu1 = wx.Menu()
       menu1.Append(MENU_FILE_EXIT, "E&xit", "Quit Application")
       # Place the Menu Item in the Menu Bar
       menuBar.Append(menu1, "&File")
       # Place the Menu Bar on the ap
       self.SetMenuBar(menuBar)
       #Define Events for the Menu Items
       wx.EVT_MENU(self, MENU_FILE_EXIT, self.CloseWindow)

       # GUI Widgets
       # Define a Text Control from which Text can be dragged for dropping
       # Label the control
       wx.StaticText(self, -1, "Text Drag Source  (left-click to select, right-click to drag)", (10, 1))
       # Create a Text Control
       self.text = wx.TextCtrl(self, DRAG_SOURCE, "", pos=(10,15), size=(350,500), style = wx.TE_MULTILINE|wx.HSCROLL)
       # Make this control a Text Drop Target
       # Create a Text Drop Target object
       dt1 = TextDropTarget(self.text)
       # Link the Drop Target Object to the Text Control
       self.text.SetDropTarget(dt1)
       # Put some text in the control as a starting place to have something to copy
       for x in range(20):
          self.text.WriteText("This is line %d of some text to drag.\n" % x)
       # Define Right-Click as start of Drag
       wx.EVT_RIGHT_DOWN(self.text, self.OnDragInit)

       # Define a Text Control to recieve Dropped Text
       # Label the control
       wx.StaticText(self, -1, "Text Drop Target", (370, 1))
       # Create a read-only Text Control
       self.text2 = wx.TextCtrl(self, -1, "", pos=(370,15), size=(410,235), style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY)
       # Make this control a Text Drop Target
       # Create a Text Drop Target object
       dt2 = TextDropTarget(self.text2)
       # Link the Drop Target Object to the Text Control
       self.text2.SetDropTarget(dt2)

       # Define a Text Control to recieve Dropped Files
       # Label the control
       wx.StaticText(self, -1, "File Drop Target (from off application only)", (370, 261))
       # Create a read-only Text Control
       self.text3 = wx.TextCtrl(self, -1, "", pos=(370,275), size=(410,235), style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY)
       # Make this control a File Drop Target
       # Create a File Drop Target object
       dt3 = FileDropTarget(self.text3)
       # Link the Drop Target Object to the Text Control
       self.text3.SetDropTarget(dt3)

       # Display the Window
       self.Show(True)

   def CloseWindow(self, event):
       """ Close the Window """
       self.Close()

   def OnDragInit(self, event):
       """ Begin a Drag Operation """
       # Create a Text Data Object, which holds the text that is to be dragged
       tdo = wx.PyTextDataObject(self.text.GetStringSelection())
       # Create a Drop Source Object, which enables the Drag operation
       tds = wx.DropSource(self.text)
       # Associate the Data to be dragged with the Drop Source Object
       tds.SetData(tdo)
       # Intiate the Drag Operation
       tds.DoDragDrop(True)


class MyApp(wx.App):
   """ Define the Drag and Drop Example Application """
   def OnInit(self):
      """ Initialize the Application """
      # Declare the Main Application Window
      frame = MainWindow(None, -1, "Drag and Drop Example")
      # Show the Application as the top window
      self.SetTopWindow(frame)
      return True


# Declare the Application and start the Main Loop
app = MyApp(0)
app.MainLoop()
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
#导入wx.Python
导入wx
#声明GUI常量
菜单\文件\退出=wx.NewId()
DRAG_SOURCE=wx.NewId()
#定义文本放置目标类
类TextDropTarget(wx.TextDropTarget):
“”“此对象实现文本的删除目标功能”“”
定义初始(自我,对象):
“”“初始化放置目标,将对象引用传递给
指示应接收删除的文本“”的内容
#初始化wx.TextDropTarget对象
wx.TextDropTarget.\uuuuuu初始化\uuuuuuuuuuuuuuuux(自)
#存储删除文本的对象引用
self.obj=obj
def OnDropText(自身、x、y、数据):
“”“实现文本删除”“”
#删除文本时,将其写入指定的对象
self.obj.WriteText(数据+'\n\n')
#定义文件放置目标类
类FileDropTarget(wx.FileDropTarget):
“”“此对象实现文件的删除目标功能”“”
定义初始(自我,对象):
“”“初始化放置目标,将对象引用传递给
指示应接收已删除文件“”的内容
#初始化wxFileDropTarget对象
wx.FileDropTarget.\uuuuu init\uuuuuuuuux(self)
#存储已删除文件的对象引用
self.obj=obj
def OnDropFiles(self、x、y、文件名):
“”“实现文件删除”“”
#出于演示目的,此函数会在小部件文本末尾附加一个文件列表
#将插入点移动到小部件文本的末尾
self.obj.SetInsertionPointEnd()
#附加已删除文件名的列表
self.obj.WriteText(“%d个文件被丢弃在%d,%d:\n”%(len(文件名),x,y))
对于文件名中的文件:
self.obj.WriteText(文件+'\n')
self.obj.WriteText('\n')
类主窗口(wx.Frame):
“”“此窗口显示GUI小部件。”“”
定义初始化(自我、父项、id、标题):
wx.Frame.\uuuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
self.setbackgroundColor(宽x.白色)
#菜单栏
#创建菜单栏
menuBar=wx.menuBar()
#构建要进入菜单栏的菜单对象
menu1=wx.Menu()
menu1.Append(菜单\文件\退出,“E&xit”,“退出应用程序”)
#将菜单项放在菜单栏中
menuBar.Append(menu1,“&File”)
#将菜单栏放在ap上
self.SetMenuBar(menuBar)
#定义菜单项的事件
wx.EVT_菜单(self,菜单文件退出,self.CloseWindow)
#GUI小部件
#定义一个文本控件,可以从中拖动文本进行拖放
#为控件添加标签
StaticText(self,-1,“文本拖动源代码(左键单击选择,右键单击拖动)”,(10,1))
#创建一个文本控件
self.text=wx.TextCtrl(self,拖动源“,”,位置=(10,15),大小=(350500),样式=wx.TE_多行| wx.HSCROLL)
#使此控件成为文本放置目标
#创建文本放置目标对象
dt1=TextDropTarget(self.text)
#将放置目标对象链接到文本控件
self.text.SetDropTarget(dt1)
#在控件中放置一些文本作为要复制的内容的起始位置
对于范围(20)内的x:
self.text.WriteText(“这是要拖动的某些文本的第%d行。\n”%x)
#定义右键单击作为拖动的开始
wx.EVT\u RIGHT\u DOWN(self.text,self.OnDragInit)
#定义文本控件以接收删除的文本
#为控件添加标签
StaticText(self,-1,“文本丢弃目标”(370,1))
#创建只读文本控件
self.text2=wx.TextCtrl(self,-1,”,pos=(370,15),size=(410235),style=wx.TE_MULTILINE | wx.HSCROLL | wx.TE_READONLY)
#使此控件成为文本放置目标
#创建文本放置目标对象
dt2=TextDropTarget(self.text2)
#将放置目标对象链接到文本控件
self.text2.SetDropTarget(dt2)
#定义文本控件以接收删除的文件
#为控件添加标签
StaticText(self,-1,“文件删除目标(仅来自非应用程序)”,(370261))
#创建只读文本控件
self.text3=wx.TextCtrl(self,-1,”,pos=(370275),size=(410235),style=wx.TE_多行| wx.HSCROLL | wx.TE_只读)
#使此控件成为文件放置目标
#创建文件放置目标对象
dt3=FileDropTarget(self.text3)
#将放置目标对象链接到文本控件
self.text3.SetDropTarget(dt3)
#显示窗口
自我展示(真实)
def关闭窗口(自身、事件):
“关上窗户”
self.Close()
def OnDragInit(自身、事件):
“”“开始拖动操作”“”
#创建一个文本数据对象,该对象保存要拖动的文本
tdo=wx.PyTextDataObject(self.text.GetStringSelection())
#创建一个拖放源对象,以启用拖动操作
tds=wx.DropSource(self.text)
#将要拖动的数据与拖放源对象关联
设置数据(tdo)
#初始化拖动操作
tds.DoDragDrop(真实)
类MyApp(wx.App):
“”“定义拖放示例应用程序”“”
def OnInit(自身):
“”“初始化应用程序”“”
#声明主应用程序窗口
frame=MainWindow(无,-1,“拖放示例”)
#显示应用程序